On Friday 09 April 2004 11:27, Muli Ben-Yehuda wrote:
> > 3. What the @$([EMAIL PROTECTED] is the difference between "my" and "local"? Which 
> > one should I use here?
> 
> http://prometheus.frii.com/~gnat/yapc/2000-stages/slide21.html

I didn't like so much the "dumbed down" type of explatanion in this
slide, so here is my take:

1. "my" does early binding between variable name and variable 
   storage (when the variable is defined) while "local" does late binding
   (when the variable is used).

2. This is very similar to the logical difference between hard link and
   symbolic link in the file system.

3. Technically, "my" variables are allocated on the call stack and thus
   behaves just like automatic variables in C. "local" variables are
   actually global variables which are looked up through the symbol table.
   What the "local" keyword does is temporarily save the global value and
   restore it automatically when we exit the scope.

4. Until perl-5 arrived (circa 94) only "local" existed. That's the
   historical reason for the non-intuitive name. During perl-6 development
   it was suggested to create a better term, something like "tempval"
   which describes more accurately its semantics (I didn't follow
   through to check if it was accepted after all).

-- 
Oron Peled                             Voice/Fax: +972-4-8228492
[EMAIL PROTECTED]                  http://www.actcom.co.il/~oron

"Beware of bugs in the above code;
 I have only proved it correct, not tried it."
                              -- Donald E. Knuth


=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to