Re: [CDBI] Updating data automatically after a search (trigger)

[prev] [thread] [next] [Date index for 2006/02/01]

From: Bill Moseley
Subject: Re: [CDBI] Updating data automatically after a search (trigger)
Date: 19:03 on 01 Feb 2006
On Wed, Feb 01, 2006 at 10:08:09AM -0500, Perrin Harkins wrote:
> It also triggers a bug in perl caused by "my $foo = 1 if $bar" 
> constructs.  Never assign to a lexical with a trailing if statement.

Perrin,

Can you point me to early docs on this?   This probably isn't a place
to discuss this issue.  But, what I read in perldelta and perldiag all
talks about the:

    my $x if 0

construct, not my $x = 1 if $bar construct.  They seem different
(even if they are not).

So, I'm not clear from the docs if the bug described in perldiag
applies to that second construct, and if so where it's documented
as such.

    Deprecated use of my() in false conditional

        (D deprecated) You used a declaration similar to my $x if 0.
        There has been a long-standing bug in Perl that causes a
        lexical variable not to be cleared at scope exit when its
        declaration includes a false conditional. Some people have
        exploited this bug to achieve a kind of static variable. Since
        we intend to fix this bug, we don't want people relying on
        this behavior. You can achieve a similar static effect by
        declaring the variable in a separate block outside the
        function, eg

            sub f { my $x if 0; return $x++ }

        becomes

            { my $x; sub f { return $x++ } }




In perldelta for perl v5.9.1:

    A new deprecation warning, Deprecated use of my() in false
    conditional, has been added, to warn against the use of the dubious
    and deprecated construct

        my $x if 0;

And is summarized in:

  http://dev.perl.org/perl5/list-summaries/2005/20050909.html

That I agree with.  Can't conditionally create a lexical.


But, to me, that seems different than:

    my $x = 1 if $bar;

which I would read as something like:

    my $x = $bar ? 1 : undef;

Or as:

    my $x;
    $x = 1 if $bar;


A quick grep of my current code doesn't find any of that usage, but I
wonder how much existing code might break if $x = 1 if $bar quit
working.


There's also the earlier:

  http://use.perl.org/articles/04/03/09/0010208.shtml

    More on the famous lexical-in-conditional deprecation warning

    Finally, Rafael changed his mind and preferred that

        my $x if $foo;

    doesn't warn anymore, and that only

        my $x if 0;

    does (clearly an abuse of the current accidental feature). The new
    form of this warning, implemented by Dave Mitchell, is now
    Deprecated use of my() in false conditional.




        -- 
        Bill Moseley
moseley@xxxx.xxx


_______________________________________________
ClassDBI mailing list
ClassDBI@xxxxx.xxxxxxxxxxxxxxxx.xxx
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi

Re: [CDBI] Updating data automatically after a search (trigger)
Bill Moseley 19:03 on 01 Feb 2006

Generated at 17:59 on 03 Feb 2006 by mariachi v0.52