Charles K. Clarkson [CKC], on Wednesday, December 8, 2004 at 08:32
(-0600) wrote about:

CKC>     What is it representative of? What is the application?
CKC> Will there be only didgits? What is the range of values
CKC> available.

ok, I rewrote that script a bit, the best solution to me is using
"sorted" hashes, so my final code should looks like:

#advanced statistics
use strict;
use warnings;
use Tie::Hash::Indexed;
use Data::Dumper;

my $depth = 8;

#result should be 'a/b/c/d'; higher in @array -> higher priority
my @array = qw (  a/b/c/d
                  a/b/c/e/f
                  a/b/e/d
                  b/a/a
                  b/a/a/a
                  );
                
tie my %hash = (), 'Tie::Hash::Indexed';                
my $result;

for my $i (1..$depth) {
        my @worka = map { /^((?:[^\/]+\/)[EMAIL PROTECTED]/]+)/ } @array;
        next unless $worka[0];
        my ($max_val, $max_key) = 0;
        %hash = ();
        for (@worka) { $hash{$_}++ }
        while ( my ($key, $val) = each(%hash) ) {
                ($max_key, $max_val) = ($key,$val) if ($val > $max_val);
        }

        @array = grep { /^$max_key/ } @array;
        print Dumper(\%hash);
        print "Winner is $max_key\n";
        $result = $max_key;
}

print "\nFinal result: $result\n";



-- 

 ...m8s, cu l8r, Brano.

[Ura Redneck if the cockroaches left a note saying 'Clean this place
up!']



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to