in reply to Re^5: Sorting out troubles with advanced-ish sort
in thread Sorting out troubles with advanced-ish sort
salva made the good that you're not looking to sort, so much as group. You don't need sort to do that.
outputsmy %conversations; while (<DATA>) { my ($src, $dst) = (split)[0, 2]; $src = pack('C4n', split(/[.:]/, $src)); $dst = pack('C4n', split(/[.:]/, $dst)); my $key = $src lt $dst ? "$src$dst" : "$dst$src"; push(@{$conversations{$key}}, $_); } foreach (values %conversations) { print(@$_); }
10.10.10.5:1001 -> 10.10.10.10:8000 10.10.10.5:1001 -> 10.10.10.10:8000 10.10.10.10:8000 -> 10.10.10.5:1001 10.10.10.6:1001 -> 10.10.10.10:8000 10.10.10.6:1001 -> 10.10.10.10:8000 10.10.10.10:8000 -> 10.10.10.6:1001 10.10.10.5:1000 -> 10.10.10.10:8000 10.10.10.5:1000 -> 10.10.10.10:8000 10.10.10.10:8000 -> 10.10.10.5:1000 10.10.10.10:8000 -> 10.10.10.5:1000 10.10.10.10:8000 -> 10.10.10.5:1000 10.10.10.6:1000 -> 10.10.10.10:8000 10.10.10.6:1000 -> 10.10.10.10:8000 10.10.10.10:8000 -> 10.10.10.6:1000 10.10.10.7:1000 -> 10.10.10.10:8000
Packing the date might now be overkill. The following should be fine:
while (<DATA>) { my ($src, $dst) = (split)[0, 2]; my $key = $src lt $dst ? "$src $dst" : "$dst $src"; push(@{$conversations{$key}}, $_); }
|
|---|