develooper Front page | perl.perl5.porters | Postings from November 2009

Re: undef $var vs $var = undef [was Re: [perl #67838] ...]

Thread Next
From:
Eric Brine
Date:
November 30, 2009 12:34
Subject:
Re: undef $var vs $var = undef [was Re: [perl #67838] ...]
Message ID:
f86994700911301234u3eed626bye1f4b8bed7ac3e12@mail.gmail.com
On Sun, Nov 29, 2009 at 5:11 AM, H.Merijn Brand <h.m.brand@xs4all.nl> wrote:

> If '$s = undef' is clearly not doing what might be expected, is there
> any chance in breaking code when making '$s = undef' to do the same as
> 'undef $s' ?
>

No, I don't see how it could.


> How easy would it be to `optimize' that in perl itself?
>

You mean remove the optimisation to prevent unnecessary calls to malloc.

The answer might depend on exactly what you want. Do you wish to free the
scalar's buffer

1) When the result of a call to undef is assigned to it?
2) When &PL_sv_undef is assigned to it?
3) When an undefined value is assigned to it?
4) When an undefined value is assigned to it and when it is cleared (e.g.
when it goes out of scope).

I'm not sure it's wise to remove this optimisation for the rare occurrence
of accidentally using undef($var) instead of $var = undef in the rare
occurrence that undef($var) is needed.

ELB


Thread Next


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