Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: How Do I Compare Array A to Array B, removing B elements from A.

by SavannahLion (Pilgrim)
on Jan 16, 2006 at 15:48 UTC ( [id://523526] : note . print w/replies, xml ) Need Help??


in reply to How Do I Compare Array A to Array B, removing B elements from A.

For anybody who comes after me, I'd like to point out in the first above example by dragonchild a minor correction. When I copied the example, I was losing the data pushed into @ArrayC. Adding a pair of ( ) on the line with grep solves the problem.
my @ArrayC = map { my $x = $_; (grep { $x =~ /^$_/ } @ArrayB) ? () : $x } @ArrayA;
I don't know if it's a typo or a change in how Perl handles the expression. I figure this note will help save someone fifteen minutes of frustration.

Originally posted as a Categorized Answer.

  • Comment on Re: How Do I Compare Array A to Array B, removing B elements from A.
  • Download Code