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

Re: my if?

July 1, 2003 21:52
Re: my if?
Message ID:
On Tue, 1 Jul 2003 10:30:34 -0400, wrote:
>On Tue, Jul 01, 2003 at 05:15:09PM +0300, Vladi Belperchinov-Shabanski wrote:
>>   my $id = 1 if $_ == 3;
>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.

As others have observed, it doesn't really make static variables since
a new pad will be used for each level of recursion.  I also think that
with multiple ithreads, each thread will use a different pad.

I don't think it was kept for backwards compatibility; I think it just
would be very difficult to make it work otherwise, though Dave
Mitchell and Gurusamy Sarathy have discussed[1] doing so (with,
surprisingly, no objections).  The problem with keeping it is that
people keep stumbling across it accidentally.

[1] Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About