Am Donnerstag, 5. Mai 2005 23.07 schrieb Ing. Branislav Gerzo:
> Hi all,
>
> just easy question, here is too much hours and my brain doesn't work
> any more. How to transform array into hash ?
>
> my @array = 1..4;
>
> I want to have:
> %hash = ( one => 1, two => 2, three => 3, four => 4 );
>
> tried something like this, but it doesnt work:
> my $hash{qw/one two three four/} = (1..4);

Another solution (beside Xavier's one) with no need to know the number of 
elements:

my $i=0; # or even: my $i;
my %hash=map {$_ => ++$i} qw /one two three four/;

joe

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


Reply via email to