in reply to Hash asignement with RE and map()
The basic code for this would be something like:
($ID,$name,$email,$title,$date,...) = /(ID)(name)(email)(title)(date)( +...)/; $hash{$ID}{name} = $name; $hash{$ID}{email} = $email; ...
Now, what you're doing is, essentially, assigning a hash slice. Now, if you don't know, a hash slice is done something like:
my @keys = ('a', 'b', 'c'); my @vals = (1, 2, 3); my %hash; @hash{@keys} = @vals;
At this point, $hash{a} == 1, etc.
For a hash of hashes, I think the syntax is something like:
my @keys = ('a', 'b', 'c'); my @vals = (1, 2, 3); my %hash; @($hash{key}}{@keys} = @vals;
But, please test this out.
To marry this with the code you have right now, I'd do something like:
my @keys = ('name', 'email', 'title', ...); ($ID, @vals) = /(ID)(name)(email)(title)(date)(...)/; @{$hash{$ID}}{@keys} = @vals;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Hash asignement with RE and map()
by bobione (Pilgrim) on Jul 03, 2001 at 23:02 UTC |