[Milan-pm] comparing 2 lists

Stefano Rodighiero stefano.rodighiero at gmail.com
Tue Oct 6 03:55:39 PDT 2009


On Tue, Oct 6, 2009 at 12:49 PM, marcos rebelo <oleber at gmail.com> wrote:

> my %hash;
> @hash{@array_num1} = ();
>
> open (my $OUT, '>', $file);
>
> foreach my $number (@array_num2) {
>    if ( exists $hash{$number} ) {
>        print "$number\n";
>        print $OUT "$number\n";
>    }
> }


The hash approach is suitable for golfing :)

[untested]

delete @h{ @an2 };
print join "\n", keys @h; # you have the list of numbers not appearing
in the second array

Or, if you put the numbers as value as long as keys:

print join "\n", delete @h{ @an2 }; # you have the list of numbers
with repetitions

s.

-- 
www.stefanorodighiero.net


More information about the Milan-pm mailing list