in reply to count number of lines with +

Gets input from user (i.e, from STDIN)

my @array = grep { /^\+\s+/, print $_ } <> ; print scalar @array;

If you pass the file name as command line argument also this script works, <> will check for @ARGV array for input file.So if you call this script as perl pattenmatch.pl filename.txtwhatever is in @ARGV is used instead.


All is well

Replies are listed 'Best First'.
Re^2: count number of lines with +
by ladnjay (Initiate) on Jul 23, 2014 at 06:30 UTC
    thanks for the reply. the script printed all the lines with and without + at start. i just want to count the number of lines starting with a + and also i need to ignore ones dont have any other characters. ex :- + abc +bc + output should be - 2 lines.

      Could you please share your sample input data, I will check with my script and let you know.


      All is well

        below is a sample. i should get the output as 2. counting lines starting by a single + and also not being the only character in the line. I know its tricky, thank you for helping me. thanks.

        +++ sdb_careers.war/body_edit_course.jsp @@ -50,7 +50,7 @@ + <option ${professionStat } + +import java.io.File; import java.sql.SQLException;