On Mon, Sep 10, 2012 at 02:45:20PM -0500, Andy Bach wrote:
> 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 ...

Actually logins on any date for the same user will overwrite
since you're assigning a hash reference to the hash element each
time. I don't think grouping by login date was a requirement so a
structure more like this might make better sense:

$VAR1 = {
    $username => [
        {
            'Login Date' => $logindate,
            'DBServer' => $dbserver,
            'Hostname' => $hostname,
            'Login Status' => $status
        },
        { ... },
        { ... },
        { ... },
    ]
};

Then you could iterate over it like so:

my @fields = (
        'Login Date',
        'DBServer',
        'Hostname',
        'Login Status',
        );

for my $user (sort keys %info) {
    print "$user\n";
    print join("\t", @fields), "\n";

    my $logins = $info{$user};

    for my $login (@$logins) {
        print join("\t", @{$login}{@fields}), "\n";
    }

    print "\n\n";
}

You'll want to read the standard perldocs to learn about data
types, slices, loops, etc. See `perldoc perl' for a list of core
perldocs that you may be interested in and begin reading. It's
really very important that you read through the core documents
when you begin. Until you do you won't be able to think of
solutions yourself.

Note that there are various ways to make the output more precise,
etc., depending on who or what will be reading it, etc. This is
just an example. You can RTFM to figure out how to make it
better. :) `perldoc -f sprintf' might be a good choice.

Regards,


-- 
Brandon McCaig <[email protected]> <[email protected]>
Castopulence Software <https://www.castopulence.org/>
Blog <http://www.bamccaig.com/>
perl -E '$_=q{V zrna gur orfg jvgu jung V fnl. }.
q{Vg qbrfa'\''g nyjnlf fbhaq gung jnl.};
tr/A-Ma-mN-Zn-z/N-Zn-zA-Ma-m/;say'

Attachment: signature.asc
Description: Digital signature

Reply via email to