in reply to using map to generate a hash of hash

As was stated by "jdporter on Nov 07, 2002 at 10:33" you pobably need to restructure the regex such that you can get all 4 variables in $1 $2 $3 (and $4 ?) and then you can do
while ($content =~ /(e)(x)(p)r/g) { $hash{$1}={ something=>$2, another=>$3 } }
But assuming that the regex is NOT under your control and that you have in fact received from somewhere else a list of N items (where N is divisble by 4) and you wish to process the entire list without creating an intermedate array then the following will do the trick (and no doubt someone could rewrite this s.t. it uses map and is on one line):
my $c=0; my @subkeys = ('', 'something', 'another', 'third'); my $k; for ( split(/(?:box)?\n\s*/) ) { if ($c) { ${$hash{$k}}}{$subkeys[$c]}=$_; } else {$k = $_ } $c = ($c + 1)%4; }
I also note that you wrote [something=>'b',another=>'c' ] which is probably wrong. If you want a hash it should be { }, if you want an array then you don't need the 'something=>' bits.

Dingus


Enter any 47-digit prime number to continue.

Replies are listed 'Best First'.
Re: Re: using map to generate a hash of hash
by Sihal (Pilgrim) on Nov 07, 2002 at 15:48 UTC
    I'm sorry but an emergency is knocking on the door; so I can't reply to jdporter and dingus right now However both of your posts are very interesting to me, I'll reply ASAP