in reply to File read and strip
dumps all the comments in @new, not the lines without comments. The corrected solution has been shown, of course.for(@array){ ($i)= grep { m/^#/ } $_; push @new, $i; }
I'd also add in a whitespace element to the regex, because I rarely start comments at the beginning of the line - I usually indent them with the rest of the code, and I doubt I'm the only one. so /^\s+#/while (<INFILE>) { next if /^#/; print OUTFILE $_; }
perl -ne '/^#/ or print' perl -pe '$_ = "" if /^#/' perl -pe '$_ x= !/^#/'
|
|---|