On Mon, Sep 10, 2012 at 7:12 AM, Danny Gratzer <[email protected]> wrote:
> while (<FILE>){
> my ($logindate, $dbserver, $hostname, $status ) = split (/,/);
> $info{$username} = {$logindate=>[$dbserver, $hostname, $status]};
> }
One thing to watch for - logins on the same day will overwrite here, so
while (<FILE>){
my ($logindate, $dbserver, $hostname, $status ) = split (/,/);
push ( @{ $info{$username}->{$logindate} }, [$dbserver,
$hostname, $status] );
}
So, when you fetch the via the key and then via the date, you're
getting back an anon array of array, which'll require one more foreach
loop, "casting" that to an array (via "@{ ... }") - this seems to
work:
my %info;
while (<DATA>){
my ($username, $logindate, $dbserver, $hostname, $status ) = split (/,/);
push ( @{ $info{$username}->{$logindate} }, [$dbserver,
$hostname, $status] );
}
use Data::Dumper;
print Dumper(\%info);
__DATA__
James,12/1/2012,foo,bar,success
James,12/1/2012,hoo,tar,fail
Bill,12/1/2012,foo,bar,success
Mark,12/1/2012,hoo,tar,fail
--
a
Andy Bach,
[email protected]
608 658-1890 cell
608 261-5738 wk
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/