On Fri, 17 Jul 2015 15:11:13 +0200
Vincent Lequertier <[email protected]> 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
>
UNTESTED:
sub ip_cmp {
my @ip_a = split /\./, $a;
my @ip_b = split /\./, $b;
for my $i ( 0 .. 3 ){
my $cmp = ( $ip_a[$i] || 0 ) <=> ( $ip_b[$1] || 0 );
return $cmp if $cmp != 0;
}
return 0;
}
for my $hash_ref ( sort ip_cmp keys %hash ){
# display $hash_ref->{$date}
}
--
Don't stop where the ink does.
Shawn
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/