in reply to Re: Deleting Elements from an Array without their Index Number?
in thread Deleting Elements from an Array without their Index Number?

I like how writing these as map+ternary makes it obvious that grep is just a specialization of map.

my @not_coin = map { $_ eq 'coin' ? () : $_} @array; # Or do you want to replace coin by undef? my @not_coin = map { $_ eq 'coin' ? undef : $_} @array;

⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Replies are listed 'Best First'.
Re^3: Deleting Elements from an Array without their Index Number?
by Anonymous Monk on Jul 24, 2006 at 15:18 UTC
    And map is a specialization of foreach+push.
    my @not_coin; foreach (@array) { push(@array, $_ eq 'coin' ? () : $_); }
    How does this help?

      How does this help? It's always good to know the more general form of your specializations. Knowing that grep is map+flat list, you can turn chained grep/map into single expressions to avoid traversing your entire list multiple times, once for each step in the chain.

      ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊