develooper Front page | perl.fwp | Postings from July 2003

Re: my if?

From:
Vladi Belperchinov-Shabanski
Date:
July 1, 2003 07:54
Subject:
Re: my if?
Message ID:
20030701175140.29cc647b.cade@biscom.net
On Tue, 1 Jul 2003 10:30:34 -0400
Ronald J Kimball <rjk@linguist.thayer.dartmouth.edu> wrote:

> On Tue, Jul 01, 2003 at 05:15:09PM +0300, Vladi Belperchinov-Shabanski wrote:
> 
> >   my $id = 1 if $_ == 3;
> 
> my has a compile time behavior and a runtime behavior.  At compile time, my
> allocates memory for the variable and adds it to the pad.  At run time, my
> resets the value of the variable.
> 
> If you put a conditional on the my statement, then the run time behavior
> does not occur when the conditional is false.  Instead of getting reset,
> the value is preserved from the previous iteration.
> 
> This was an accidental feature that is now kept for backwards
> compatibility, because some programmers have used it to create static
> variables.  It's best to avoid it, however.
> 

I was wandering around similar explanation (yet missing compile time
behaviour) but carring older values is stunning and far from obvious :)

thanx.

> 
> Ronald
> 

P! Vladi.
ps: excuse me for the accidental `reply' instead of `new' :/ :)
--
Vladi Belperchinov-Shabanski <cade@biscom.net> <cade@datamax.bg>
Personal home page at http://soul.datamax.bg/~cade
DataMax SA   http://www.datamax.bg
Welcome to this crazy world, welcome to the show that never ends...



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About