Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^3: A better (ie.more concise) way to write this?

by Laurent_R (Monsignor)
on Dec 13, 2013 at 18:55 UTC ( #1067054=note: print w/ replies, xml ) Need Help??


in reply to Re^2: A better (ie.more concise) way to write this?
in thread A better (ie.more concise) way to write this?

Then , if you want to modify an existing data structure, what about using the fact that modifying $_ will modify the original array? Something like this, shown under the debugger:

DB<1> @a = 1..9; DB<2> map{ $_ = ++$_% 10 } @a; DB<3> x @a 0 2 1 3 2 4 3 5 4 6 5 7 6 8 7 9 8 0 DB<4>
Well, this obviously works, but something like $c = ++$c is, I believe, not defined in C and probably also not in Perl (i.e. the implementor if free to do whatever). It could be changed to:
map { $_ ++; $_ = $_ % 10} @a;
This would probably be more secure against any change of implementation.


Comment on Re^3: A better (ie.more concise) way to write this?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2015-07-28 11:34 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 (254 votes), past polls