I tired this first and am running into an error. I am very new at Perl so may be missing how the subroutine is set up. I run my script witht he following (my actual arrays have many more words than that in my sample):
my @sets = (\@array1, \@array2, \@array3, \@array4 );
for my $h (0..$#sets) {
for my $j ($h+1..$#sets) {
compute_stuff($sets[$h], $sets[$j]);
}
}
Sub union_intersection {
my ($set1, $set2) = @_;
my (%union, %intersect);
foreach my $e (@$set1, @$set2) {
$union{$e}++ && $intersect{$e}++
}
my @intersect = sort keys %intersect;
#print FILEOUT "@intersect\n";
print FILEOUT scalar @intersect;
print FILEOUT "\n";
}
I get a syntax error on 2 lines. One on this line:
my (%union, %intersect);
The other near the last line (with '}').
Not sure why. In you example you did't have the semi-colon at the end and added it but that wasn't it. Also, don't I need to call the subroutine somewhere for it to work. Not sure if this an error on my part (e.g. not sure what compute_stuff should be doing).
Thanks for the help-
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.