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

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

Thread Next
Eric Brine
November 30, 2009 12:34
Re: undef $var vs $var = undef [was Re: [perl #67838] ...]
Message ID:
On Sun, Nov 29, 2009 at 5:11 AM, H.Merijn Brand <> 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.


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