in reply to deleting lines from file
one 111 ury th ese llin it, thenyour program makes absolutely no sense. Since this smells like homework, here are some questions I am asking myself, and then a proposed solution that the prof probably won't accept ;) :
N.B. This solution is quite cost effective memory-wise, because Tie::File does some cool behind-the-scenes stuff so you don't have to read everything in at once. This is huge if the file is very large.#!/usr/bin/perl use strict; use warnings; use Tie::File; my $value_to_delete = <STDIN>; chomp $value_to_delete; tie my @file, 'Tie::File', "file" or die "Couldn't open: $!"; @file = grep { $_ ne $value_to_delete } @file; untie @file;
#!/usr/bin/perl -pi.orig BEGIN {$value_to_delete = <STDIN>} undef $_ if $_ eq $value_to_delete;
|
|---|