Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Replacing values in an array

by eyepopslikeamosquito (Chancellor)
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 making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2015-07-29 05:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (260 votes), past polls