Ing. Branislav Gerzo [IBG], on Wednesday, December 8, 2004 at 14:28
(+0100) wrote these comments:

IBG> Ok, here is my solution, not the best one, because it return random
IBG> value if max is not exactly defined (we ends with the same values for
IBG> strings)

ok, if anyone interested - I change it a bit, and this is last version
:)
works, as was defined at start.

#advanced statistics
use strict;
use warnings;
use Data::Dumper;

my $depth = 3;

my @oarray = (  'a/1/5/2',      #this one should be result
                'a/1/1/1',
                'a/1/3/1',
                '2/1/1/1',
                '2/1/1/1',
                );
                
my @array = @oarray;
                
my %hash = ();          
for my $i (1..$depth) {
        my @worka = map { /^((?:[^\/]+\/)[EMAIL PROTECTED]/]+)/ } @array;
        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";
}

#getting the right value
my $id = 0;
while ( my $key = each(%hash) ) {
        for my $i (0..$#oarray) {
                $id = $i if ($i < $id && $oarray[$i] =~ /^$key/);
        }
}

(my $result = $oarray[$id]) =~ s/^((?:[^\/]+\/)[EMAIL PROTECTED]/]+).*/$1/g;
print "\nFinal result: $result";

-- 

 ...m8s, cu l8r, Brano.

[Hey!  Scott!  You're back!  How was the treatment program?]



-- 
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