in reply to Re^2: Cleaner way of looping through a file and stripping only certain lines?
in thread Cleaner way of looping through a file and stripping only certain lines?

Yes it is. But so is any in-place edit.

A safer answer would be to use File::Temp. You still have a problem with power failure but your window of problems is smaller.

## UNTESTED use File::Temp 'tempfile'; use File::Copy; my ($tmp_FH,$tmp_fn) = tempfile(); open(IN, '<', $ifile) or die "Couldn't open file: $!\n"; my @data = <IN>; close IN; foreach my $line (@data) { ### Do what you want print $tmp_FH "$line"; } copy($tmp_fn,$ifile);

grep
XP matters not. Look at me. Judge me by my XP, do you?

  • Comment on Re^3: Cleaner way of looping through a file and stripping only certain lines?
  • Download Code