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


in reply to Re: Replacing values in an array
in thread Replacing values in an array

Using for instead of map:

use strict; use warnings; use Data::Dumper; my @a = ("M94202", "M94150", "M94297", "M94150", "M94161", "M94161", " +M94162"); my ( $n, %h ) = -1; $_ = $h{$_} //= $n+=2 for @a; print Dumper \@a;

I suppose if you were playing golf, without use strict, you might write:

my ( $n, %h ) = -1; $_ = $h{$_} //= $n+=2 for @a;
in one-line as:
$_=$h{$_}//=$}+=2-!$}for@a;
(/me ducks)