halfcountplus has asked for the wisdom of the Perl Monks concerning the following question:
Then i got the number of instances using McDarren's code from Counting in regular expressions and did this:my $all = do {local $/; <IN>};
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)?#!/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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: ranking number of occurances
by ikegami (Patriarch) on Mar 16, 2008 at 22:37 UTC | |
|
Re: ranking number of occurances
by FunkyMonk (Bishop) on Mar 16, 2008 at 22:45 UTC | |
by ikegami (Patriarch) on Mar 16, 2008 at 23:42 UTC | |
|
Re: ranking number of occurances
by grizzley (Chaplain) on Mar 17, 2008 at 07:51 UTC |