Last week, I requested help in a script that would compare two lists, and print the
results in a third list - the results being just the items that occured in BOTH lists.
You came thru with some good help. Posted below is the script I used - including some
slight modifications for my web site.
Now I have another request. Instead of printing the results on the browser poge, I
need it to be in a list just as list 1 and list 2 are. Also, rather than listing the
actual items in the script, I need the script to open the file of list 1 and the file
of list 2, compare, and print to list 3. Lets say the three files would be in
$cgi.admin/testing
Thanks again for your good suggestions! ( I am strictly a novice, but am trying to
learn :)
The script that works for printing on the browser page:
#!/usr/bin/perl
# get list of all users
$cgi=$ENV{'SITE_CGIROOT'};
$html=$ENV{'SITE_HTMLROOT'};
print "Content-type: text/html\n\n";
use strict;
my @list1 = ('apple', 'orange', 'lemon', 'tangerine', 'grape');
my @list2 = ('apple', 'tangerine', 'grape', 'banana');
my @list3 = ();
foreach my $i (@list2)
{
if (grep /^$i$/, @list1)
{
push(@list3, $i);
}
}
print join ", ", @list3; #should print "apple, tangerine, grape"