Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Is using $#array Frowned on?

by eyepopslikeamosquito (Canon)
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 perusing the Monastery: (15)
As of 2014-11-21 18:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (114 votes), past polls