Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: replacing order element in array

by NetWallah (Canon)
on Apr 18, 2007 at 18:43 UTC ( [id://610816]=note: print w/replies, xml ) Need Help??


in reply to replacing order element in array

Yet another (more perl-ish) way to do it :
my @a = (1,2,3,4,5,6); my @b=(1,5,3,6,8,2,4); my %aref = map {$_=>\$_} @a; my $cand; # Candidate value to replace the selected value exists ($aref{$_}) or $cand=$_,last for @b; ${$aref{3}}=$cand; # Assuming you want the value "3" replaced print @a; #--Output -- #128456

     "Choose a job you like and you will never have to work a day of your life" - Confucius

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-20 01:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found