Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Hash of array of hashes

by monarch (Priest)
on Jul 08, 2005 at 06:38 UTC ( #473348=note: print w/replies, xml ) Need Help??


in reply to Hash of array of hashes

Solved!

use strict; my $exampleinput = q(1 | p1=v1,p2=v2 | p3=v3,p4=v4); sub processrow( $ $ ) { my ( $hashref, $input ) = @_; my @condition = split( /\s*\|\s*/, $input ); my $index = shift( @condition ); $hashref->{$index} = [ map { { map { $_->[0] => $_->[1] } map { [ split( /=/, $_ ) ] } map { split( /,/, $_ ) } $_ } } @condition ]; } my %examplehash = (); processrow( \%examplehash, $exampleinput ); { use Data::Dumper; print( Dumper( \%examplehash ) ); }

Produces:

$VAR1 = { '1' => [ { 'p2' => 'v2', 'p1' => 'v1' }, { 'p3' => 'v3', 'p4' => 'v4' } ] };

Replies are listed 'Best First'.
Re^2: Hash of array of hashes
by Anonymous Monk on Jul 08, 2005 at 06:51 UTC
    Thanks, that was really fast and really good.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://473348]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2020-05-28 07:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (165 votes). Check out past polls.

    Notices?