in reply to Re: Sorting out troubles with advanced-ish sort
in thread Sorting out troubles with advanced-ish sort
Ok, so it looks like your nudge nudged me enough. The loop now looks like this:
for my $line( map { $_->[2] } sort { $a->[0] cmp $b->[0] || $a->[1] <=> $b->[1] } map { my @vals = split /\s/, $_; my( $sourceserv, $sourceport ) = (split /:/, $vals +[0])[0,1]; my( $destserv, $destport ) = (split /:/, $vals[2] +)[0,1]; my( $low, $high ) = sort { $a cmp $b } ( "$sourceserv:$sourceport", "$destserv:$destpor +t" ); my( $key ) = $low . '-' . $high; [ $key, $sourceport , $_ ] } <DATA> ){ print $line; }
And the output as desired:
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.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: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.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.7:1000 -> 10.10.10.10:8000
Is this efficient? I don't know. Will it run "fast enough"? Also don't know. But I suppose I could let it chug along while I'm here on a Saturday, and if it's still running after I leave, so be it :) (Please don't ask how large the capture file is ;)
Thanks much!
$,=42;for(34,0,-3,9,-11,11,-17,7,-5){$*.=pack'c'=>$,+=$_}for(reverse s +plit//=>$* ){$%++?$ %%2?push@C,$_,$":push@c,$_,$":(push@C,$_,$")&&push@c,$"}$C[$# +C]=$/;($#C >$#c)?($ c=\@C)&&($ C=\@c):($ c=\@c)&&($C=\@C);$%=$|;for(@$c){print$_^ +$$C[$%++]}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Sorting out troubles with advanced-ish sort
by japhy (Canon) on May 06, 2006 at 18:02 UTC | |
by ikegami (Patriarch) on May 06, 2006 at 19:18 UTC | |
by chargrill (Parson) on May 08, 2006 at 17:22 UTC | |
by ikegami (Patriarch) on May 08, 2006 at 17:53 UTC | |
|
Re^3: Sorting out troubles with advanced-ish sort
by johngg (Canon) on May 06, 2006 at 20:20 UTC |