And not a map() in sight!use Data::Dumper; my @data = ( qq{key1~key2~key3 Value for key1, key2, key3}, qq{key4~key5~key6 Value for key4, key5, key6}, qq{key7~key8~key9 Value for key7, key8, key9} ); my %hash; for(@data) { my($value, @keys) = reverse /(\w+)(?:~|$)/g, /\n(.*)/; @hash{@keys} = ($value) x @keys; } print Dumper( \%hash ); __output__ $VAR1 = { 'key7' => 'Value for key7, key8, key9', 'key8' => 'Value for key7, key8, key9', 'key9' => 'Value for key7, key8, key9', 'key1' => 'Value for key1, key2, key3', 'key2' => 'Value for key1, key2, key3', 'key3' => 'Value for key1, key2, key3', 'key4' => 'Value for key4, key5, key6', 'key5' => 'Value for key4, key5, key6', 'key6' => 'Value for key4, key5, key6' };
_________
broquaint
In reply to Re: Splitting an array to populate hash
by broquaint
in thread Splitting an array to populate hash
by Coruscate
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |