Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Is using $#array Frowned on?

by eyepopslikeamosquito (Chancellor)
on Feb 14, 2014 at 21:06 UTC ( #1075003=note: print w/ replies, xml ) Need Help??


in reply to Is using $#array Frowned on?

An example of where you should avoid the $#array notation is when counting from the end of an array (see Perl Best Practices, chapter 5, "Use negative indices when counting from the end of an array"). For example, you should replace:

$frames[$#frames ] = $active{top}; $frames[$#frames-1] = $active{prev}; $frames[$#frames-2] = $active{backup};
with:
$frames[-1] = $active{top}; $frames[-2] = $active{prev}; $frames[-3] = $active{backup};
because it is easier on the eye and avoids the undesirable repetition of the frames variable name (DRY).


Comment on Re: Is using $#array Frowned on?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2015-07-29 03:12 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 (260 votes), past polls