loris has asked for the wisdom of the Perl Monks concerning the following question:
Hello Map-Happy Monks,
I thought I could extract a subset fom a list by doing this:
my @allFruit = qw/apple apricot banana coconut/; my @someFruit = map { if ($_ =~ m/^[ap]/) { $_;} } @allFruit; print "no. of some fruit: " . scalar(@someFruit) . "\n"; print "some fruit: " . join('*',@someFruit) . "\n";
This however produces this output:
no. of some fruit: 4 some fruit: apple*apricot**
rather than
no. of some fruit: 2 some fruit: apple*apricot
which was what I wanted.
What would be the best way of doing such extraction?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Extracting subset from list: map unsuitable?
by gaal (Parson) on Apr 13, 2005 at 07:37 UTC | |
|
Re: Extracting subset from list: map unsuitable?
by borisz (Canon) on Apr 13, 2005 at 07:39 UTC | |
by loris (Hermit) on Apr 13, 2005 at 07:46 UTC | |
|
Re: Extracting subset from list: map unsuitable?
by Zaxo (Archbishop) on Apr 13, 2005 at 07:49 UTC | |
|
Re: Extracting subset from list: map unsuitable?
by bart (Canon) on Apr 13, 2005 at 07:56 UTC | |
|
Re: Extracting subset from list: map unsuitable?
by rev_1318 (Chaplain) on Apr 13, 2005 at 07:46 UTC |