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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.