jeffa has asked for the wisdom of the Perl Monks concerning the following question:
my @words = ('one-', 't-wo', 'three- fo-ur', 'five six se-ven');
My goal is to remove all dashes and split the elements on white space, i.e. I want the new list to look like:
qw(one two three four five six seven)
The question: (drum roll please)
why does this work:
and this one does not:print join("\n", map { $_ =~ s/-//g; split; } @words);
print join("\n", map { $_ =~ s/-//g } map { split } @words);
I know it has something to do with what the right map statement returns: does it return a reference to an array or an array?
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Fun with learning maps
by chromatic (Archbishop) on Jun 27, 2000 at 01:24 UTC | |
by jeffa (Bishop) on Jun 27, 2000 at 01:30 UTC | |
|
RE: Fun with learning maps
by Adam (Vicar) on Jun 27, 2000 at 01:46 UTC | |
|
RE: Fun with learning maps
by Anonymous Monk on Jun 28, 2000 at 01:37 UTC | |
by jeffa (Bishop) on Jun 28, 2000 at 01:54 UTC |