Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Replacing values in an array

by toolic (Bishop)
on Jan 26, 2013 at 23:07 UTC ( #1015542=note: print w/ replies, xml ) Need Help??


in reply to Replacing values in an array

Use a hash:

use strict; use warnings; use Data::Dumper; my @array = ("M94202", "M94150", "M94297", "M94150", "M94161", "M94161 +", "M94162"); my %uniq; my $z = 1; for (@array) { if (/M/) { if (exists $uniq{$_}) { $_ = $uniq{$_}; } else { $uniq{$_} = $z; $_ = $z; $z += 2; } } } print Dumper(\@array); __END__ $VAR1 = [ 1, 3, 5, 3, 7, 7, 9 ];


Comment on Re: Replacing values in an array
Download Code
Replies are listed 'Best First'.
Re^2: Replacing values in an array
by tonto (Friar) on Jan 26, 2013 at 23:23 UTC
    Thank you, it WORKS !!!!!

    I really must overcome my fear of hashes now, thank you also for that encouragement.
    -tonto

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (15)
As of 2015-07-28 18:26 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