>From the previous emails, I do not understand what
parts of this code is doing and why is this practical?
The part is $union{$e} = 1  and $isect{$e} = 1 .
Also %count is never used.

thank you
derek


use warnings;

@a = (1, 3, 5, 6, 7, 8);
@b = (2, 3, 5, 7, 9);

@union = @intersect= ();
%union = %intersect = ();
#%count = ();

foreach $e (@a) { 
    $union{$e} = 1 
}
print "union output:\t",%union,"\n";
## output is 816111317151

foreach $e (@b) {
    if ( $union{$e} ) { 
        $isect{$e} = 1 
    }
    $union{$e} = 1;
}
@union = keys %union;
@isect = keys %isect;

print @union;
print "\n";
print @isect;

--- Tom Phoenix <[EMAIL PROTECTED]> wrote:

> On 8/23/06, Andrej Kastrin <[EMAIL PROTECTED]>
> wrote:
> 
> > below is simple solution for union and
> intersection for a pair of
> > arrays (@a and @b). How to modify this example
> that I can
> > calculate union and intersection for each pair of
> "n" arrays.
> 
> Use a pair of nested loops; the outer picks one item
> from the n
> arrays, the inner picks a second. Inside, call your
> current code once
> for each pair of arrays.
> 
> Hope this helps!
> 
> --Tom Phoenix
> Stonehenge Perl Training
> 
> -- 
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
> <http://learn.perl.org/>
> <http://learn.perl.org/first-response>
> 
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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