Phoenix.pm: map + grep problem

Victor Odhner vodhner at cox.net
Mon May 5 11:08:58 CDT 2003


Here's a really basic Perl construct that for some reason I've never 
used.  In this case I'm trying to take the intersection of two arrays, 
and this seemed appropriate to me:

  @a1=(a,b,c,d);
  @a2=(b,d,f);
  print( ( map{grep /^$_$/, @a2} @a1 ), "\n");

What I get is bdfbdfbdfbdf.

It doesn't seem that $_ is being set to each element
of @a1 and then grepped against @a2.

Can anybody explain my blind spot here?

Again, I just want a list that is the intersection
of the two lists.  Of course I can run a loop, but
"map" seems a nice tight way to do the job.

Vic




More information about the Phoenix-pm mailing list