http://www.perlmonks.org?node_id=11104683


in reply to The error says the value is uninitialized, but it works anyway

The homework question just defines @colors and @drop and says to remove the things in drop from colors, that's it.

If perl was math we could say:


@colors - @drop = @colors

But perl is perl so we have to say:

@colors = -@drop + @colors

Perl can do that, like this:

@colors = (miniature @drop program here) @colors

The flow of information goes:
      __<________________________<__
   #4/                              \#3
@colors = (miniature > program > here) @colors
         #2\__<___________________<___/#1

The mini program goes inside map {} like:

@colors = map { my $x = join '|', @drop; /$x/ ? () : $_ } @colors;

Unrolled:

@colors =
  map {
    my $x = join '|', @drop; # make a regex
    /$x/ ? () : $_           # simpler than it looks
  }
@colors;