Perhaps someone answer this and I missed it but:
%hast = map{split(/=/)} @list;
should work..
Matt Doughty BOT BSC Japan
-Original Message-
From: Dirk Bremer [mailto:[EMAIL PROTECTED]]
Sent: 13"N3OEZ14"รบ 5:01
To: perl-win32-users
Subject: Assigning Hash From an Array
I want to assign k
>> -Original Message-
>> From: Dirk Bremer [mailto:[EMAIL PROTECTED]]
>> Sent: Tuesday, March 13, 2001 2:30 PM
>> To: [EMAIL PROTECTED]
>> Subject: Re: Assigning Hash From an Array
>>
>>
>> I received two suggestions:
>>
>&
processing.
wantor
> -Original Message-
> From: Dirk Bremer [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, March 13, 2001 2:30 PM
> To: [EMAIL PROTECTED]
> Subject: Re: Assigning Hash From an Array
>
>
> I received two suggestions:
>
> %hash = map {split(/=
Try this:
%hash = map{ /(\w*)=(.*)/ } @a;
Of course, if your keys contain more then just 'word' characters, you'll
want to change that \w to something else. (\.)? would work, as it will stop
once it hits the equal sign, but that might not be very efficient with
backtracking.
-rev
Message: 6
R
Try this...
use strict;
my @list = ("a=1","b=2","c=3");
my %hash = map { my @elt = split /=/, $_; $elt[0] => $elt[1]} @list;
for (keys %hash) {
print "\$hash{$_} = $hash{$_}\n";
}
which prints
$hash{a} = 1
$hash{b} = 2
$hash{c} = 3
You have to split a scalar; you cannot split a
>>What I would like is to use the split function on each list element,
>>splitting on the "=", so that "a" would be a key, "1" would be
>>a value, etc. I have tried various combinations to get this to work.
>>So far, no luck. I was thinking along the lines of:
#! perl -w
use strict;
my @list =
> From: "Dirk Bremer" <[EMAIL PROTECTED]>
> To: "perl-win32-users" <[EMAIL PROTECTED]>
> Subject: Assigning Hash From an Array
> Date: Tue, 13 Mar 2001 14:01:08 -0600
> Organization: NISC
>
> I want to assign key/value pairs to a hash from a list. The list
> would be as follows:
>
> @list = ("a
I received two suggestions:
%hash = map {split(/=/)} @list;
%hash = ( map( split( /=/, $_), @list) );
I had tried something vary similar to the first example. The first example does work,
I have not tried the second example. What is
the magic with the parentheses in the first example?