CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
line counter

 



ladnjay
New User

Jul 23, 2014, 2:48 AM

Post #1 of 2 (286 views)
line counter Can't Post

hi all,
i need a script that can count number of lines that starts with a + sign. also ignore lines with only a + sign and starts with multiple + signs. for below sample the script should output value of 2.


+++ sdb_careers.war/body_edit_course.jsp
@@ -50,7 +50,7 @@

+ <option ${professionStat }
+

+import java.io.File;
import java.sql.SQLException;


BillKSmith
Veteran

Jul 23, 2014, 7:25 AM

Post #2 of 2 (281 views)
Re: [ladnjay] line counter [In reply to] Can't Post

Your example requires you to also ignore lines which consist only of white space.


Code
use strict; 
use warnings;
my $count;
while (<DATA>) {
$count++ unless /^[+]+/ or /^\s*$/;
}
print $count;
__DATA__
+++ sdb_careers.war/body_edit_course.jsp
@@ -50,7 +50,7 @@

+ <option ${professionStat }
+

+import java.io.File;
import java.sql.SQLException;

Good Luck,
Bill

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives