in reply to Array name with a Variable
To solve your problem, just use an array of references to your set arrays:foreach my $e (@array1, @array2) { $union{$e}++ && $intersect{$e}++ }
Your union/intersection code will now look like:my @sets = (\@array1, \@array2, ...); for my $i (0..$#sets) { for my $j ($i+1..$#sets) { compute_stuff($sets[$i], $sets[$j]); } }
sub union_intersection { my ($set1, $set2) = @_; my (%union, %intersection) for my $e (@$set1, @$set2) { ... } ... }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Array name with a Variable
by godevars (Initiate) on Apr 17, 2008 at 20:29 UTC |