Hi Guys,
I am trying to print blank lines on using perl command line.
cat blank.dat
Hello
### Blank line commented for visibility ####
Second Blank Line
### Blank line commented for visibility ####
Command 1 :
perl -npe 'if ($_ == m/^$/) {print "This is a blank line \n"}' blank.dat
Output :
This is a blank line
Hello
### Blank line commented for visibility ####
This is a blank line
Second Blank Line
### Blank line commented for visibility ####
Command 2 :
perl -npe 'if (/^$/) {print "This is a blank line \n"}' blank.dat
Output :
Hello
This is a blank line
### Blank line commented for visibility ####
Second Blank Line
This is a blank line
I don't understand the order of print statements using command 1 .
Command 2 prints everything in the file , plus the print statements .
Shouldn't both the above should print just print statements ?
If I write a small perl program using while loop , it just works fine. But commandline behavior is different .
I am sure I am missing some important subtle points being a beginner in perl
thanks,
I am trying to print blank lines on using perl command line.
cat blank.dat
Hello
### Blank line commented for visibility ####
Second Blank Line
### Blank line commented for visibility ####
Command 1 :
perl -npe 'if ($_ == m/^$/) {print "This is a blank line \n"}' blank.dat
Output :
This is a blank line
Hello
### Blank line commented for visibility ####
This is a blank line
Second Blank Line
### Blank line commented for visibility ####
Command 2 :
perl -npe 'if (/^$/) {print "This is a blank line \n"}' blank.dat
Output :
Hello
This is a blank line
### Blank line commented for visibility ####
Second Blank Line
This is a blank line
I don't understand the order of print statements using command 1 .
Command 2 prints everything in the file , plus the print statements .
Shouldn't both the above should print just print statements ?
If I write a small perl program using while loop , it just works fine. But commandline behavior is different .
I am sure I am missing some important subtle points being a beginner in perl
thanks,