At 11:29 AM +0530 9/3/10, Jatin Davey wrote:

Any reason to use named variables than to use the default variable ($_) ?

Two reasons that I know:

1. If you use a named variable, you and everybody else reading your code will know what it is for. While it doesn't matter much for 3-line loops, short programs tend to turn into longer ones, and then you really should be using named variables.

2. The default variable $_ can get clobbered by some operations. If you use $_, you have to be careful to avoid such operations. It is much better not to have to worry.

Quiz for extra credit: Uri's program has a misleadingly-named variable. Can you figure out what it is?

--
Jim Gibson
j...@gibson.org

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to