my $file = "c:/test.txt"; # open file for both reading and writing open FILE, "+<$file" or die "Can't open $file: $!\n"; my @file = <FILE>; # get all data make_backup($file, @file); # make a backup seek FILE, 0, 0; # go to beginging of file truncate FILE, 0; # delete all the old data # now write only the lines we want back to file # the newlines are still attached to each line for my $line (@file) { print FILE $line unless $line eq "don't print\n"; } close FILE; # sub to write a backup sub make_backup { my $file = shift; open BACKUP, ">$file.bak" or die "Can't write $file.bak: $!\n"; print BACKUP @_; close BACKUP; }
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
In reply to Re: remove new lines in flat files
by tachyon
in thread remove new lines in flat files
by wickedxter
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |