Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
No such thing as a small change
 
PerlMonks  

Re^2: Replacing values in an array

by eyepopslikeamosquito (Canon)
on Jan 27, 2013 at 01:31 UTC ( #1015556=note: print w/ replies, xml ) Need Help??


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)


Comment on Re^2: Replacing values in an array
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1015556]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (10)
As of 2014-04-24 11:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (565 votes), past polls