Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
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 chilling in the Monastery: (13)
As of 2015-05-05 15:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    In my home, the TV remote control is ...









    Results (120 votes), past polls