Ing. Branislav Gerzo [IBG], on Wednesday, December 8, 2004 at 13:03
(+0100) wrote:

IBG> I think this is nice example for recursive function, do you agree ?

I agree too :)

IBG> Ok, I am code that, so I am looking for your suggestions, too :)

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

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

my $depth = 3;

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


-- 

 ...m8s, cu l8r, Brano.

[Virginity can be cured.]



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