in reply to using map to generate a hash of hash
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):while ($content =~ /(e)(x)(p)r/g) { $hash{$1}={ something=>$2, another=>$3 } }
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.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; }
Dingus
|
|---|
| 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 |