I'm trying to return an array of "shared" members between two arrays (strings).
Now my subroutine seems to work, but I can't read the return array.
I suspect I'm passing a pointer to an array rather than an array, or something similar... but this is practically right from the textbook:
http://www.unix.org.ua/orelly/perl/cookbook/ch10_06.htm Any advice would be great, not much of a programmer!
here's the call:
@sharemem = SharedMembers(\@grparray1,
\@grparray
2);
print "Shared mem @sharedmem[0]\n";
the subroutine:
sub SharedMembers {
my($arr1, $arr2) = @_;
my @arr3;
my $n = 0;
for ($i=0;$i < @$arr1; $i++)
{
for ($j=0; $j < @$arr2; $j++)
{
if($arr1->[$i] eq $arr2->[$j])
{
$arr3[$n] = ($arr3[$n],$arr1->[$i]);
$n++;
print "Match on $arr1->[$i] $arr2->[$j]\n";
}
}
}
print "arr3x0 @arr3[0]\n";
return @arr3;
}
the output:
Match on Local Admins Local Admins
Match on XXX Class B XXX Class B
Match on Domain Users Domain Users
Match on XXX All XXX All
Match on xxx xxx
Match on xxxc xxxc
arr3x0 Local Admins
Shared mem
What I'm looking for is
Shared mem Local Admins :(