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

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

by sundialsvc4 (Monsignor)
on Dec 17, 2013 at 00:31 UTC ( #1067397=note: print w/ replies, xml ) Need Help??


in reply to A better (ie.more concise) way to write this?

Now the dust has settled on this one, I have a question ... yes, a question ...

My solution to this problem came up more-or-less like this:

perl -e 'use strict; use warnings; my @a = ( 1..10 ); foreach (@a) { $_ = ( $_ + 1 ) % 10; }; use Data::Dumper; print Data::Dumper->Dump([\@a], ["a"]);' $a = [ 2, 3, 4, 5, 6, 7, 8, 9, 0, 1 ];

In other words, using the foreach() construct to iterate through the list/array, with $_ being an automatic alias to each entry in succession, rather than actually indexing into the array.   Intuitively, this seems to me that this would be “more efficient.”   Is it?

Also... among the various solutions that were proffered in this thread, how much difference in timing are we actually talking about here?


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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2014-08-22 23:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (168 votes), past polls