Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2017-05-22 17:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?