How09 has asked for the wisdom of the Perl Monks concerning the following question:
The data file looks like this:my $fname = "while_multi_cond.dat"; my $s1 = ""; open( FP, "<", $fname ) or die "Can't open $fname: $!"; while(<FP>) { if (/^_start/) { # This works as expected # while(<FP> ) { # if (/^_stop/) { last } # I'm trying to replace it with this: while( (<FP>) && (!/^_stop\n/) ) { # but seems to break the functionality of $_ $s1 .= $_; } } if ($_) { print("$_") } } print("\$s1= \n<$s1>");
In the program output below you can see how $_ retains the value obtained in the outer loop:The file: while_multi_cond.dat ----- no1 no2 _start yes 1 yes 2 _stop no3 no4 ----------
Why doesn't $_ contain the new lines as they are read in? Thanks, Howard~> ./while_multi_cond.pl parse_data> ./while_multi_cond.pl no1 no2 _start $s1= <_start _start _start _start _start _start >
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: using multiple conditionals in a while(test)
by BrowserUk (Patriarch) on Dec 04, 2010 at 06:57 UTC | |
by jwkrahn (Abbot) on Dec 04, 2010 at 07:12 UTC | |
by BrowserUk (Patriarch) on Dec 04, 2010 at 07:51 UTC | |
by How09 (Novice) on Dec 04, 2010 at 14:25 UTC |