in reply to don't want to print certain lines
Second, you seem to be testing whether a line contains nothing but ");" with a bare if. Newsflash: ");" as a string has a true value. You need a better test. And "=" is not the proper comparison operator.
The following code would appear to do what you want:
while ($string=<IN>) { if ($string=~ /^FIELD/) { while($line=<IN>) { last if $line =~ /^\);$/; } } else { @lines=split(/\s+/,$string); print "@lines\n"; } }
Something else to reconsider: Apparently you treat ");" on a line of its own as special. Perhaps you should reconsider setting $/ to it, treating it as a "line" terminator? That might make things easier.
local $/ = ");\n"; local $\ = $/; while ($string=<IN>) { if ($string=~ /^FIELD/) { # no need to skip anything, everything is in $string } else { chomp $string; # get rid of trailing ");" # print will add it again, thanks to $\ @lines=split(/\s+/,$string); print "@lines\n"; } }
|
|---|