>>>>> "JG" == Jim Gibson <jimsgibson@gmail.com> writes:
JG> At 11:29 AM +0530 9/3/10, Jatin Davey wrote:
>> Any reason to use named variables than to use the default variable ($_) ?
JG> Two reasons that I know:
JG> 1. If you use a named variable, you and everybody else reading your
JG> code will know what it is for. While it doesn't matter much for 3-line
JG> loops, short programs tend to turn into longer ones, and then you
JG> really should be using named variables.
JG> 2. The default variable $_ can get clobbered by some operations. If
JG> you use $_, you have to be careful to avoid such operations. It is
JG> much better not to have to worry.
JG> Quiz for extra credit: Uri's program has a misleadingly-named
JG> variable. Can you figure out what it is?
and john pointed it out already so no cheating. a brainfart on my part.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
|