Ken Foskey wrote:
On Sun, 2007-08-12 at 22:55 -0400, yitzle wrote:
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?

This is not elegant in this example but it possibly is the answer you
are looking for.

  my %ages{ 'alice', 'bob', 'charles'}  = @r;


#!/usr/bin/perl

use strict;
use warnings;

use Data::Dumper;

my @people = ( 'alice', 'bob', 'charles' );
my @list = ( 1, 2, 3 );

my %ages = ();
@ages{ @people } = @list;

print Dumper \%ages;

__END__

--
Just my 0.00000002 million dollars worth,
 Shawn

"For the things we have to learn before we can do them, we learn by doing them."
 Aristotle

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


Reply via email to