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:
in one-line as:my ( $n, %h ) = -1; $_ = $h{$_} //= $n+=2 for @a;
(/me ducks)$_=$h{$_}//=$}+=2-!$}for@a;
|
---|
In Section
Seekers of Perl Wisdom