in reply to Mutually Exclusive Elements
The VALUES of the hash indicate the source array it came from.my %h; my $n=3; sub add{ my ($n,$v,@a)=@_; (%h < $n and not exists $h{$_} and $h{$_}=$v ) for @a }; add($n, # Allow $n unique elements 1, # This is the First array to be added # Numbers below are the contens of the array to be added 3,4,5,6,3,2,4,1); # First set of numbers $n+=$n; # Now increase the number of elements allowed add($n,2,4,3,2,7,8,2); # Second set of numbers print qq($_ => $h{$_} \n) for sort keys %h --OUTPUT--- 2 => 2 3 => 1 4 => 1 5 => 1 7 => 2 8 => 2
Yes - this can be optimized, and use of the global %h can be avoided - enhancements left as an exercise.
...each is assigned his own private delusion but he cannot see the baggage on his own back.
|
|---|