[Dub-pm] hello

Fergal Daly fergal at esatclear.ie
Fri Jul 23 17:59:18 CDT 2004

On Fri, Jul 23, 2004 at 08:15:55PM +0100, Aidan Kehoe wrote:
>     my $certain_value = $sbh->selectall_arrayref->($sh, # [1]
>        undef, $good_row_id);
>     if (defined $certain_value && defined $certain_value->[0]->[0]) {
>         $certain_value = $certain_value->[0]->[0];
>     } else {
>         $certain_value = 'default value';
>     }
> Why did line [1] even compile? What does it mean, given that it did? "Call
> the result of selectall_arrayref with no arguments, and pass $sh, undef, and
> $good_row_id as _its_ argument list?" Selectall_arrayref returns a reference
> to an array, which, Jesus, should refuse to be called as a function. We're
> not assembler. Nor even buffer-overflow-inclined C.

It compiled because Perl is a dynamic language and Perl does not know in
advance that selectall_arrayref will not be returning a subroutine
reference. It's perfectly valid code for suitable values of $sbh.

> But, even more mad, looking back over the four months that major brain fart
> was running code, how in God's name did it sometimes Do The Right Thing? 
> Because it did; looking back through the records for those four months,
> there's no other explanation for them than that it did--$certain_value ended
> up as the right, non 'default value' string perhaps one time in five that
> the code ran. Was there random reading of values off some conceptual stack? 

That code should have died every time with an error like "Not a CODE
reference at blah blah".

Have you used eval anywhere in your code? That is the only reason I can
think of that the problem hasn't shown up sooner. If it was executing inside
an eval and you weren't checking $@ after the eval then that could hide the
fact that your code was dying.

> Can I turn on something stronger than -W to catch this shit in the future?

Beyond rewriting it all in a strongly-typed language like Haskell (or a
badly-typed language like Java) there is nothing you can do,


More information about the Dublin-pm mailing list