[Milan-pm] comparing 2 lists

Paola Bisignano paola.bisignano at gmail.com
Tue Oct 6 04:23:26 PDT 2009


sorry, I want only repetitions...

2009/10/6 Stefano Rodighiero <stefano.rodighiero at gmail.com>:
> 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
> _______________________________________________
> Milan-pm mailing list
> Milan-pm at pm.org
> http://mail.pm.org/mailman/listinfo/milan-pm
>


More information about the Milan-pm mailing list