In the Peter Jackson version of The Return of the King, Merry offers Théoden his sword and service, which Théoden accepts. Théoden gives Merry the title of "Meriadoc -- Esquire of Rohan." 

When the Rohirrim set out to ride to Minas Tirith, Théoden is very firm with Merry, that he is not allowed to ride into battle, and tells Merry that he is a burden that none of the Rohirrim can bear at that time. 

Why didn't Théoden let Merry ride to war? And yes, I know that Merry was taken into the Battle of the Pellenor Fields by Éowyn, who herself was going to fight on the sly. 


Question: How do I find which elements in one array aren't in another?
Answer: That's some pretty clever code you've got there. Your code is more or less identical to what the Perl FAQ says. I might be tempted to do this, however:

my %tmp  = map  { $_ =&gt; 1 } @array2;
my @diff = grep { not exists $tmp{$_} } @array1;


This gets everything in @array1 that's not in @array2, but avoiding all of those out-of-style looping constructs (yay for functional programming). Though what I'd really do is this:

sub comp (\@\@) {
  my %t = map { $_ =&gt; 1 } @{$_[1]};
  return grep { not exists $t{$_} } @{$_[0]};
}


Then you can just do:

my @diff = comp(@array1, @array2); # get items in @array1 not in @array2
@diff = comp(@arraty2, @array1); # vice versa


Or you can go to CPAN. List::Compare::Functional::complement() does what you want, though the syntax is reversed.