-----Original Message-----
>From: yitzle <[EMAIL PROTECTED]>
>Sent: Aug 12, 2007 10:55 PM
>To: "beginners@perl.org" <beginners@perl.org>
>Subject: Array to Hash
>
>I got an array of values where the order is relevent, eg the ages of
>Alice, Bob and Charles, and I want to make a hash out of it. I got
>this code that does it:
>  my %ages = (alice => $r[0], bob => $r[1], charles => $r[2]);
>Is there a more elegent way to do it?
>

using hash slice.

@ages{qw/alice bob charles/} = @r;

--
Jeff Pang <[EMAIL PROTECTED]>
http://home.arcor.de/jeffpang/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to