in reply to Regex in a printfile?
That's pretty inefficient as it will read in all of the matching lines from your input before it prints things out.
That aside, if you want to remove comments from all lines before printing and remove empty lines completely you probably want something more like this.
while( <INFILE> ) { chomp; s/^\s*#.*$//; next unless length $_; print OUTFILE $_, "\n"; }
Update: As is remarked below, the s/// needs to be anchored. And yes, this skips empty lines. Now where's my caffeine . . .
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex in a printfile?
by ikegami (Patriarch) on Nov 15, 2006 at 20:29 UTC | |
by johngg (Canon) on Nov 15, 2006 at 20:53 UTC |