Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
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??

Help for this page

Select Code to Download


  1. or download this
    use strict;
    use warnings;
    ...
    my ( $n,  %h ) = -1;
    $_ = $h{$_} //= $n+=2 for @a;
    print Dumper \@a;
    
  2. or download this
    my ( $n,  %h ) = -1;
    $_ = $h{$_} //= $n+=2 for @a;
    
  3. or download this
    $_=$h{$_}//=$}+=2-!$}for@a;
    

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 perusing the Monastery: (12)
As of 2015-07-28 19:09 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 (258 votes), past polls