in reply to Flip flop operator

You exhaust <> in your first pass. Unfortunately, you can't seek in tty STDIN, so you'll need to invert your logic, making all your comparisons in a single pass of <>. I don't think your range operators will take the same form in that rewrite.

If you mean to iterate over a seekable handle, you'll still probably be better off to only read once.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: Flip flop operator
by ysth (Canon) on Aug 19, 2004 at 13:22 UTC
    I have the feeling you missed the $ARGV[0]= line.
Re^2: Flip flop operator
by sashac88 (Beadle) on Aug 19, 2004 at 08:19 UTC
    I don't have much expirience with PERL.
    I need to take off specific lines from some file.
    How should I do it?
    Thanks in advance for the answer!

      It is probably simpler to just slurp the entire file into an array and replace the while(<>) with an iteration over the array (untested code follows):

      my @data = <>; my $backup=$commandfile.".bak"; foreach $com (keys %hashnew) { $ARGV[0]="$backup"; $^I=".bak"; foreach (@data) { if ($hashnew{$com} == "all") { unless (/$hashnew{$com}/../\*\ Exit\ context\ \*/) { s/$com//g; } } if (/$hashnew{$com}/../\*\ Exit\ context\ \*/) { s/$com//g; } print; } }
      Of course if you actually explained to us what you want to do we might be able to come up with a better suggestion as it is not entirely clear from your code.

      /J\