in reply to File read and strip
The other problem is with the grep: you're only collecting lines that start with a #, although you say you want to do the opposite.
You seem to be doing a lot of unnecessary looping too. I suggest the following as a more streamlined alternative:
use strict; use warnings; print "Input file name? "; my $name_in = <>; chomp $name_in; print "output file name? "; my $name_out = <>; chomp $name_out; open my $in, '<', $name_in or die "error opening $name_in: $!"; open my $out , '>', $name_out or die "error opening $name_out: $!"; print $out grep { !/^#/ } <$in>;
|
|---|