Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Counting the Times Two Unknown Values Appear Together

by naikonta (Curate)
on Jul 15, 2007 at 03:08 UTC ( #626682=note: print w/replies, xml ) Need Help??

in reply to Counting the Times Two Unknown Values Appear Together

Well, assuming that you can spot the position and save it as $sport, then you already have something to compare with. If I'm not mistaken, do you mean something like (untested):
my %count; my $total; while (<FILE>) { chomp; my($src, $sport) = (split /;/)[9,12]; my $number_of_sport_shows_on_this_line = () = /$sport/gi; $count{$.} = $number_of_sport_shows_on_this_line; $total += $number_of_sport_shows_on_this_line; } # iterate %count to see how many the pattern shows up on each line # $total is the total number the pattern shows up in the file
If you avoid regexes:
my(%count, $total); while (<FILE>) { chomp; my @fields = split /;/; my %seen; $seen{$_}++ for @fields; my $target = $fields[12]; $count{$.} = $seen{$target}; $total += $seen{$target}; }

Update: (15-07-2007) I misread the title, I missed the "appear together" part, and I second kyle's reply.

Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2021-08-06 03:48 GMT
Find Nodes?
    Voting Booth?
    My primary motivation for participating at PerlMonks is: (Choices in context)

    Results (44 votes). Check out past polls.