[EMAIL PROTECTED] wrote:
In the script below, I have an array @datas with its elements consisting of numbers like this :-


Out of the above list, I wish to generate a seperate array so that among their elements, there should not be any 2 numbers that can match and so the output should be :- 1 2 3
            1 6 7
            4 5 10

I therefore have written the script below and have tested the script to be working. What is the easier way to write this script?

As usual, hashes can be useful to simplify things. In the code suggestion below I made use of the 'array of hashes' @numbers.

    my $numbers_wanted = 2;
    my ( @datawanted, @numbers );

    LOOP: foreach ( @datas ) {
        my @test = split;
        foreach my $num ( @numbers ) {
            next LOOP if grep( $num->{$_}, @test ) >= $numbers_wanted;
        }
        push @datawanted, $_;
        push @numbers, { map { $_ => 1 } @test };
    }

    print "$_\n" for @datawanted;

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

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


Reply via email to