in reply to Re: Back to Remedial Perl for Me: map{} function
in thread Back to Remedial Perl for Me: map{} function
If I read your statement correctly ( and I may not have ), the first use of map isn't correct
But this usage is correctmy @first = qw/ one-1 two-2 three-3/; my %hash = map { split /-/ } @first; # Which works for me btw print map { "$_ => $hash{$_}\n" } keys %hash;
my @first = qw/ one-1 two-2 three-3/; my @second = map { split /-/ } @first; my %hash = @second; # Legal code, isn't it? print map { "$_ => $hash{$_}\n" } keys %hash;
How else is map supposed to make @first into @second except by performing an action on every element of @first?
I am not arguing that a foreach wouldn't be appropriate here. If that is what works, by all means use it. But if I am not supposed to use map when I want an action on every element of an array, doesn't it make more sense to say
because that seems to be the only option you have left me with this statement.@second = @first;
Would you be kind enough to expand on your answer so I can figure out what I missed?
TIA
mikfire
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Back to Remedial Perl for Me: map{} function
by merlyn (Sage) on Dec 15, 2000 at 20:35 UTC | |
by mikfire (Deacon) on Dec 15, 2000 at 20:39 UTC | |
|
Re: Re: Re: Back to Remedial Perl for Me: map{} function
by $code or die (Deacon) on Dec 15, 2000 at 21:05 UTC | |
by davorg (Chancellor) on Dec 15, 2000 at 21:07 UTC | |
by Anonymous Monk on Dec 15, 2000 at 21:35 UTC | |
by $code or die (Deacon) on Dec 15, 2000 at 22:21 UTC | |
by chipmunk (Parson) on Dec 15, 2000 at 22:34 UTC | |
by davorg (Chancellor) on Dec 15, 2000 at 22:29 UTC |