I want to compare the number of times a string occurs in a set of files. I read each file into a single line using:
my $all = do {local $/; <IN>};
Then i got the number of instances using McDarren's code from Counting in regular expressions and did this:
#!/usr/bin/perl -w use strict; my $bit="ace"; my (%hash); while (<DATA>) { if ($_ =~ /$bit/) { my @ray=($_ =~ /$bit/g); my $c=scalar @ray; $hash{$_}=$c; } } my @rank=sort{$hash{$b}<=>$hash{$a}}keys%hash; print @rank; __DATA__ In the wire game, a "mob" composed of dozens of grifters simulates a "wire store", i.e., a place where results from horse races are received by telegram and posted on a large board, while also being read aloud by an announcer. The griftee is given secret foreknowledge of the race results minutes before the race is broadcast, and is therefore able to place a sure bet at the wire store. In reality, of course, the con artists who set up the wire store are the providers of the inside information, and the mark eventually is led to place a large bet, thinking it to be a sure win. At this point, some mistake is made, which actually makes the bet a loss.
Is there a less troublesome way to do this? Even better, is there a way to correspond a hash key to an array value without "whiling" thru -- so i could invoke the number of occurances (from %hash) to the sorted array value (which would equal the name of a hash key)?

In reply to ranking number of occurances by halfcountplus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.