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

Perrin Harkins perrin at elem.com
Wed Feb 1 19:35:36 GMT 2006

On Wed, 2006-02-01 at 11:03 -0800, Bill Moseley wrote:
> Can you point me to early docs on this?

It's a little hard to Google for, but it has come up on many mailing
lists and on Perlmonks.  I found an old mail I wrote about this, so here
is more explanation:

sub sticky {
   my $arg = shift;
   my $object = Some::Package->new() if $arg;
   $object ||= Other::Package->new();

The first time you run it with $arg = 0, you will get the expected
result.  The second time through with $arg = 0, you will find the
Other::Package object from last time in $object and it will not get a
fresh Other::Package object assigned to it.  So, if you never put
anything in $object when the conditional is false, you won't actually
trigger the bug.  Probably safest to just avoid using the "... if $arg"
syntax at all, but don't panic if you see some in your old code.

Attached is a test program that demonstrates the issue.  The hash ref
should be different every time the sub foo() is called, but it isn't.

> 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

I am so happy to see this!  Fantastic!

Anyway, this one is so slippery that I think the only way to stay sane
is to NEVER declare a lexical with a postfix if statement.  Picking out
the ones where it breaks from the ones where it doesn't takes more spare
brainpower than I have.

- Perrin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.pl
Type: application/x-perl
Size: 153 bytes
Desc: not available
Url : http://lists.digitalcraftsmen.net/mailman/private/classdbi/attachments/20060201/9dbf64c3/test.bin

More information about the ClassDBI mailing list