in reply to Re^2: removing comments
in thread removing comments
variant 2:open (my $in, "<", $ARGV[0]) or die "in: $@"; open (my $out, ">", "$ARGV[0].new") or die "out: $@"; while( my $line = <$in>) { print $out $line unless $line =~ /^#/; } close $in; close $out;
Note that you cannot erase a line from the middle of a file, you will always have to write a new one. But you already knew that, didn't you? ;-)open (my $in, "<", $ARGV[0]) or die "in: $@"; my @lines = grep { not /^#/ } <$in>; #<> here in list context, therefo +re no explicit loop
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: removing comments
by GrandFather (Saint) on Jun 21, 2007 at 20:42 UTC |