Hi Vincent, On Mon, 20 Jul 2015 09:18:33 +0200 Vincent Lequertier <s...@riseup.net> wrote:
> Thank you for the help, but this does not work. We needa pass the ip > addresses to the sorting function, because actually the keys of the hash > are the dates > > $VAR1 = '[15/Jul/2015:10:30:03 +0200]'; > $VAR2 = { > 'ip' => 'xxx.xxx.xxx.xxx', > 'action' => 'GET xxx' > }; > > The workaround I found is to loop over the hash, push an array with the > ip addresses, and sort them, like this : > > sub sort_by_ip { > my @ip; > for my $key (keys %hash) { > push @ip, $hash{$key}{ip}; > } Why not do “push @ip, [$key => $hash{$key}{$ip}];” here instead and then sort based on the IPs, extract the keys and use foreach? > my @ip_sorted = map { $_->[0] } > sort { $a->[1] <=> $b->[1] } > map { [$_, int sprintf("%03.f%03.f%03.f%03.f", > split(/\./, $_))] } @ip; > } > > So I'm looking for a way to iterate through the hash in the order of my > array. > > Regards Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ List of Text Processing Tools - http://shlom.in/text-proc “Publish or Perish” → “Life or Death” — http://unarmed.shlomifish.org/2615.html Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/