my %count;
while (<FILE>) {
my( $src, $sport ) = (split /;/)[9,12];
$count{$src,$sport}++; # magic $;
}
for my $pair ( sort keys %count ) {
print "($pair) occurred on a line together $count{$pair} times\n";
# if you need the two parts:
# my( $src, $sport ) = split $;, $pair;
}
In fact, I'd extend it to any number of fields:
my @fields = ( 9, 12 );
my %count;
while (<FILE>) {
chomp;
$count{ (split /;/)[@fields] }++;
}
for ( sort keys %count ) {
print "($_) occurred on a line together $count{$_} times\n";
# if you need the parts:
# my @vec = split $;;
}
|