in reply to Help on foreach loop

It would seem that your regex isn't matching on subsequent passes. Since you never reset it, it won't be undef, it will be whatever it used to be.
@ARGV = <$responseDir/*>; undef $newFile; # Force reset while (<>) { $newFile = $ARGV, print(STDERR "Found $commonField\n"), last +if /^"$commonField"$/; } print "my newFile to change is $newFile\n";

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^2: Help on foreach loop
by Anonymous Monk on Sep 09, 2004 at 15:32 UTC
    it still dosen't reset $newFile, for the first iteration $newFile = sample.txt in the next iteration $newFile is still sample.txt, and in my script I clearly move the sample.txt to another diretory after it was found the first time,
      Sounds like $ARGV isn't changing, possibly because the file isn't closed? Try closing ARGV within the while loop:
      @ARGV = <$responseDir/*>; while (<>) { $newFile = $ARGV, close ARGV, last if /^"$commonField"$/; }

      Caution: Contents may have been coded under pressure.