in reply to Difference Quantity of two Arrays

Your problem is that that outer map() will return something for each element of @dbs. You probably wanted a grep() there, but even that is problematic.

You should really be thinking "hash" when you want to check if an item is in a set:

sub create_list { my @skip_dbs = @_; # declare the hash my %skippables; # populate the hash with the skippables $skippables{$_}++ for @skip_dbs; my @dbs = qw/fetch forward user smtp/; # return a list of each element of @dbs # that isn't in the skippables hash return grep { ! $skippables{$_} } @dbs; } my @list = create_list("user", "smtp"); print "@list";

Replies are listed 'Best First'.
Re^2: Difference Quantity of two Arrays
by ocs (Monk) on Jan 02, 2007 at 14:54 UTC

    Thanks all for your answers and especially the explanation of ikegami.

    But what does the ++ after $skippables{$_} do?

    # populate the hash with the skippables $skippables{$_}++ for @skip_dbs;

      It's the increment operator.

      When dealing with numbers (or undef),
      $a++
      means
      $a = $a + 1
      except it won't issue a warning if $a is undefined.