Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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).

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 browsing the Monastery: (4)
As of 2016-06-30 02:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred method of making French fries (chips) is in a ...











    Results (388 votes). Check out past polls.