Front page | perl.perl5.porters |
Postings from November 2009
Re: [perl #67838] lvalue substr keeping lexical alive
Thread Previous
From:
H.Merijn Brand
Date:
November 29, 2009 02:12
Subject:
Re: [perl #67838] lvalue substr keeping lexical alive
Message ID:
20091129111143.509f5d83@pc09.procura.nl
On Sun, 29 Nov 2009 00:51:49 +0100, Eirik Berg Hanssen
<Eirik-Berg.Hanssen@allverden.no> wrote:
> > On Fri, Nov 27, 2009 at 8:52 AM, H.Merijn Brand <h.m.brand@xs4all.nl> wrote:
> >> On Fri, 27 Nov 2009 15:38:03 +0100, Eirik Berg Hanssen
> >
> >>> Did you mean undef($s), or did something change while I was not
> >>> looking? ;-)
> >>
> >> Both is allowed, but indeed only 'undef ($x)' frees the variable.
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' ?
How easy would it be to `optimize' that in perl itself?
> Aside: If anything were to change, my suggestion would be the
> addition of a warning for an assignment, the right hand side of which
> is a simple literal undef (without arguments, parens or such). It is
> often a mistake and never the clearest way to write something:
>
> $x = undef; # unclear – did you really mean this?
> $x = (); # same thing, clearer – yes, I mean it
> undef $x; # not the same thing: this frees the memory
>
> @x = undef; # unclear – did you really mean this?
> @x = (undef); # same thing, clearer – yes, I mean it
> @x = (); # not the same thing: empty array
> undef @x; # not the same thing: this frees the memory
>
> %x = undef; # unclear – did you really mean this?
> %x = ('' => undef); # same thing, clearer – and no warning
> %x = (); # not the same thing: empty hash
> undef %x; # not the same thing: this frees the memory
>
> ($x, @y) = undef; # unclear – did you really mean this?
> ($x, @y) = (undef); # same thing, clearer
> ($x, @y) = (); # also the same thing, perhaps even clearer
> undef $x; undef @y; # not the same thing: this frees the memory
>
> lsub($x) = undef; # ... okay, I suppose that one is reasonably clear
> lsub($x) = (undef); # same thing, even clearer ;-)
> undef lsub($x); # not the same thing ... but yes, it works ;-)
>
>
> ... and at least the scalar case is a mistake that, apparently, even
> an experienced Perl hacker could make. ;-)
>
>
> Eirik
--
H.Merijn Brand http://tux.nl Perl Monger http://amsterdam.pm.org/
using & porting perl 5.6.2, 5.8.x, 5.10.x, 5.11.x on HP-UX 10.20, 11.00,
11.11, 11.23, and 11.31, OpenSuSE 10.3, 11.0, and 11.1, AIX 5.2 and 5.3.
http://mirrors.develooper.com/hpux/ http://www.test-smoke.org/
http://qa.perl.org http://www.goldmark.org/jeff/stupid-disclaimers/
Thread Previous