On 7/10/09 Fri  Jul 10, 2009  11:32 AM, "Matteo Riva" <mura...@gmail.com>
scribbled:

> Hello everybody, I have two lists and I want to merge them like this:
> 
>     element 1 of list A, element 1 of list B, A2, B2, A3, B3, etc.
> 
> I need this to create a sequence of key/value for an anonymous hash.
> 
> I'm using this code:
> 
>     # @fields contains the names of the hash keys
>     # $val is a string containing a colon-separated sequence of vales to
>     # be associated with the keys
> 
>     my $count = 0;
>     $data{$key} = { map { $fields[$count++] => $_ } split (/:/, $val) };
> 
> which uses a counter variable.  I was wondering it there's a more
> elegant (AKA perlish) way to mix two lists in this way.

Use a hash slice:

my %data;
@da...@fields} = split(/:/,$val);




-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to