Thank you for the help, Charles! Unfortunately, I'm not able to figure out how to access the element of %ordered, despite some diggings in the perldoc (http://perldoc.perl.org/perldsc.html). I can print a single element with print $ordered{'xxx.xxx.xxx.xxx'}[0]{'[15/Jul/2015:10:30:03 +0200]'}{action};

But I don't find how to get the dates e.g. '[15/Jul/2015:10:30:03 +0200]'

Here is what I've tried:

tie( my %ordered, 'Tie::IxHash', map { ( $_,[ ] ) }   @ip );

while ( my($key,$value) = each %hash ) {
    push @{$ordered{$value->{ip}}}, {$key, $value};
}
#print Dumper \%ordered;
my $i = 1;
for my $key (keys %ordered) {
    print "ip number $i : $key\n";
    for my $entry (@{$ordered{$key}}) {
        print $entry . "\n";
    }
    ++$i;
}

But this module seems to be the way to go.

--
Vincent Lequertier
vincentlequertier.tk

Le 2015-07-17 23:19, Charles DeRykus a écrit :
Another approach using Tie::IxHash:

use Tie::IxHash;
use Data::Dumper;
use feature 'say';

my @ip = (...)
my %hash = (...);

tie( my %ordered, 'Tie::IxHash', map { ( $_,[ ] ) }   @ip );

while ( my($key,$value) = each %hash ) {
    push @{$ordered{$value->{ip}}}, {$key,$value};
}
say Dumper \%ordered;

Leaving exact details of printing as an exercise for reader...

--
Charles DeRykus

On Fri, Jul 17, 2015 at 6:11 AM, Vincent Lequertier <s...@riseup.net> wrote:
Hi,

I have the following structure :

$hash{$date} = {
                    'ip'     => $ip,
                    'action'   => $action,
                };

witch produce data like :

$VAR1 = '[15/Jul/2015:10:30:03 +0200]';
$VAR2 = {
          'ip'     => 'xxx.xxx.xxx.xxx',
          'action' => 'GET xxx'
        };

and an array of ip addresses, say @ip

My question is how can I display the content of %hash in the order of @ip,
assuming %hash has the same length as @ip ?

Thank you

--
Vincent Lequertier
vincentlequertier.tk

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to