Rob Dixon wrote:
Rodrick Brown wrote:
@list = map { $c = $_; $c =~ s/\s+/_/g; $c } @d = grep { /\d/ } <FH>;
Is there a way to shorten the following mostly concerned with why I
have to use a temporary variable.
The temporary variable is there because modifying $_ would alter the
contents of the @d array which is presumably required intact.
Putting all of this into a single statement doesn't make for readable
programming. It is much better as:
my @d = <FH>;
my @list = @d;
s/\s+/_/g foreach @list;
You forgot the grep:
my @d = grep /\d/, <FH>;
my @list = @d;
s/\s+/_/g foreach @list;
But of course you could put that all on one line:
s/\s+/_/g for my @list = my @d = grep /\d/, <FH>;
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/