in reply to A perverse use of grep
One style rule I strongly recommend is:my @lines = map { s/^\s+//; s/#.*//; s/\s+$//; length($_) ? $_ : () } +<$in>;
Never modify $_ in a map.If you think of map as transforming one list to another, modifying $_ makes it "unclean", because it also edits the input list! This can lead to subtle bugs, and is best avoided always, rather than permitted occasionally, such as in this code.
So, I'd rewrite that trivially as:
my @lines = map { local $_ = $_; s/^\s+//; s/#.*//; s/\s+$//; length($ +_) ? $_ : () } <$in>;
-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: modifying $_ in map (was Re: A perverse use of grep)
by johnnywang (Priest) on Jun 15, 2005 at 17:29 UTC |