•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Perl section within the Software Development category of DaniWeb, a massive community of 429,891 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,325 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Perl advertiser: Programming Forums
Views: 1433 | Replies: 5 | Solved
Here's one I haven't been able to find an answer to. I have 4 arrays:
@array1, @array2, @array3, @array4. I ran code to compare the values of 2 arrays to see number of values in common:
I was thinking, if I wanted to compare all pairs of arrays and values they had in common, I could create a loop that started with @array1 and compared it to each array. In th loop I would make the digit in the array name a variable. For example:
As you probably know already, the @array$i variable doesn't work.
In the end I'm looking to have a grid where I see belwo but was starting witht he basics:
array1 array2 array3 array4
array1 10 5 17 2
array2 5 15 8 1
array3 17 8 14 6
array4 2 1 6 19
I could create an outer loop that would have tha array names each witha variable in the foreach loop.
Thanks-
@array1, @array2, @array3, @array4. I ran code to compare the values of 2 arrays to see number of values in common:
use strict;
use warnings;
my (%union, %intersect);
foreach my $e (@array1, @array2) {
$union{$e}++ && $intersect{$e}++
}
my @intersect = sort keys %intersect;
print FILEOUT "@intersect\n";
print FILEOUT scalar @intersect;I was thinking, if I wanted to compare all pairs of arrays and values they had in common, I could create a loop that started with @array1 and compared it to each array. In th loop I would make the digit in the array name a variable. For example:
use strict;
use warnings;
my (%union, %intersect, $i);
while ($i <6) {
foreach my $e (@array1, @array$i) {
$union{$e}++ && $intersect{$e}++
}
my @intersect = sort keys %intersect;
print FILEOUT "@intersect\n";
print FILEOUT scalar @intersect;
$i++;
}As you probably know already, the @array$i variable doesn't work.
In the end I'm looking to have a grid where I see belwo but was starting witht he basics:
array1 array2 array3 array4
array1 10 5 17 2
array2 5 15 8 1
array3 17 8 14 6
array4 2 1 6 19
I could create an outer loop that would have tha array names each witha variable in the foreach loop.
Thanks-
•
•
•
•
•
•
•
•
DaniWeb Perl Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Problem in Reading Array Variable (C)
- constructor with an array as an argument (C++)
- encapsulating an array in a class? (C#)
- Homework: filling array from text file (VB.NET)
- Array Values not found in Methods (Java)
- Resizing of an array. (C++)
- Array declaration problem (C++)
- How do I create a program using an Array ? (C++)
Other Threads in the Perl Forum
- Previous Thread: count characters in a string
- Next Thread: How to lock SDBM file when that file is writing by multiple programs at the same time



Threaded Mode