I don't get how you can actually print the contents of the subhash.
foreach my $user(keys %info){
print $info{$user}; #This gives me hash
print $user, "\n" #Here I can retrieve the usernames that
were made hash keys
}
Now here is where I hit a dead end. I'm not exactly sure how you are
going to loop through the contents of a logindate.
On Mon, Sep 10, 2012 at 8:12 PM, Danny Gratzer <[email protected]> wrote:
> I would create a hash with hash references containing the date and an
> anonymous array as members. Something like this:
>
> open FILE , 'C:\test.csv' or die $!;
> my %info
>
> while (<FILE>){
> my ($logindate, $dbserver, $hostname, $status ) = split (/,/);
> $info{$username} = {$logindate=>[$dbserver, $hostname, $status]};
> }
>
> On Mon, Sep 10, 2012 at 6:44 AM, andrew sison <[email protected]>
> wrote:
>>
>> Hi,
>>
>> I'm confronted with this problem.I've done this before but I just
>> can't remember how.
>>
>> There is a log file I am trying to parse:
>>
>> open FILE , 'C:\test.csv' or die $!;
>> while (<FILE>){
>> my ($logindate, $dbserver, $hostname, $status ) = split (/,/);
>>
>> }
>>
>> Now I want to use the $username as a name of a hash (sort of
>> dynamically create a variable.
>>
>> So if in the end I want to print all the login records of let's say
>> user "James", I would have a report like this:
>>
>>
>> James
>> Login Date DBServer Hostname Login Status
>> Aug 5 mailserver mail.co.xx Success
>> Sep 3 dnsserver dns.co.xx failed
>>
>>
>> Aron
>> Login Date DBServer Hostname Login Status
>> Jan 5 ftpserver ftp.co.xx Success
>> Oct 3 sshserver ssh.co.xx Success
>>
>>
>> I'm really lost here. I know I have to use some sort of nested hashes
>> but I just couldn't figure it out.
>>
>> --
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>> http://learn.perl.org/
>>
>>
>
>
>
> --
> Danny Gratzer
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/