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

Bill Moseley moseley at hank.org
Wed Feb 1 19:03:15 GMT 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 at hank.org





More information about the ClassDBI mailing list