in reply to Make calculation with values from hash
1st line 2nd line, next line is just a newline 4th line, next line spaces and newline 6th and last line
this script that uses your construct
use strict; use warnings; my $inFile = q{spw592594.dat}; open my $inFH, q{<}, $inFile or die qq{open: $inFile: $!\n}; while (<$inFH>) { chomp; next unless $_; print qq{-->$_<--\n}; } close $inFH or die qq{close: $inFile: $!\n};
produces
-->1st line<-- -->2nd line, next line is just a newline<-- -->4th line, next line spaces and newline<-- --> <-- -->6th and last line<--
and, as you can see, the line with spaces does not get rejected and the empty line does. A string of spaces is boolean true. Changing the script to
... while (<$inFH>) { chomp; # reject if 0 or more spaces anchored to start and end next if m{^\s*$}; print qq{-->$_<--\n}; } ...
does reject correctly and produces
-->1st line<-- -->2nd line, next line is just a newline<-- -->4th line, next line spaces and newline<-- -->6th and last line<--
I hope this is of use.
Cheers,
JohnGG
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Make calculation with values from hash
by GertMT (Hermit) on Jan 02, 2007 at 20:20 UTC | |
by johngg (Canon) on Jan 02, 2007 at 20:54 UTC |