jlongino has asked for the wisdom of the Perl Monks concerning the following question:
I want replace the foreach (@array) with something like this: %hash = map {# what the heck goes here?} @array; I haven't used map much, but would like to start using it more often where appropriate. Maybe the question should be "Is it appropriate in this example?". TIA,use strict; use warnings; my @array = qw(key1:value1 key2:value2 key3:value3); my (%hash, $key, $val); foreach (@array) { ($key, $val) = split ":"; $hash{$key} = $val; } print "\$hash{$_} = $hash{$_}\n" foreach keys %hash;
--Jim
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using map to split an array to hash key/values
by Masem (Monsignor) on Dec 18, 2001 at 02:45 UTC | |
by Juerd (Abbot) on Dec 18, 2001 at 02:52 UTC | |
|
Re: Using map to split an array to hash key/values
by FoxtrotUniform (Prior) on Dec 18, 2001 at 02:40 UTC | |
|
Re: Using map to split an array to hash key/values
by mortis (Pilgrim) on Dec 18, 2001 at 02:40 UTC | |
|
Re: Using map to split an array to hash key/values
by Juerd (Abbot) on Dec 18, 2001 at 02:44 UTC | |
|
Re: Using map to split an array to hash key/values
by jlongino (Parson) on Dec 18, 2001 at 02:53 UTC | |
by grinder (Bishop) on Dec 18, 2001 at 03:24 UTC | |
|
Re: Using map to split an array to hash key/values
by strat (Canon) on Dec 18, 2001 at 19:32 UTC | |
|
Re: Using map to split an array to hash key/values
by jsegal (Friar) on Dec 18, 2001 at 02:44 UTC |