Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^4: array refernce as hash value

by ashish.kvarma (Monk)
on Jul 22, 2009 at 10:53 UTC ( [id://782247]=note: print w/replies, xml ) Need Help??


in reply to Re^3: array refernce as hash value
in thread array refernce as hash value

Are you looking for something similar to :
use strict; use Data::Dumper; my %hash; while (<DATA>) { chomp; my ($key, $value) = split /\|/, $_; my @values = split /,/, $value; if (defined $hash{$key}) { push @{$hash{$key}}, \@values; } else { $hash{$key} = [\@values]; } } print Dumper \%hash; __DATA__ 9344220001|sei10720013,21/07/2009-00-00-00,23/07/2009-12-34-44 9344220001|sei10720014,23/07/2009-20-00-23 9344220002|sei10720015,21/07/2009-00-00-00,23/07/2009-12-34-44 9344220003|sei10720016,23/07/2009-20-00-23 9344220003|sei10720017,23/07/2009-20-00-23 9344220003|sei10720018,23/07/2009-20-00-23
Output is as followed:
$VAR1 = { '9344220003' => [ [ 'sei10720016', '23/07/2009-20-00-23' ], [ 'sei10720017', '23/07/2009-20-00-23' ], [ 'sei10720018', '23/07/2009-20-00-23' ] ], '9344220002' => [ [ 'sei10720015', '21/07/2009-00-00-00', '23/07/2009-12-34-44' ] ], '9344220001' => [ [ 'sei10720013', '21/07/2009-00-00-00', '23/07/2009-12-34-44' ], [ 'sei10720014', '23/07/2009-20-00-23' ] ] };
I hope this helps.
Regards,
Ashish

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2024-04-19 15:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found