Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: Counting the Times Two Unknown Values Appear Together

by jdporter (Canon)
on Jul 16, 2007 at 02:36 UTC ( #626764=note: print w/replies, xml ) Need Help??


in reply to Re: Counting the Times Two Unknown Values Appear Together
in thread Counting the Times Two Unknown Values Appear Together

I'd simplify it a bit further:

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 $;; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://626764]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (9)
As of 2018-11-20 15:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My code is most likely broken because:
















    Results (227 votes). Check out past polls.

    Notices?