Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Hash of array of hashes

by monarch (Priest)
on Jul 08, 2005 at 06:38 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://473348]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-03-28 17:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found