in reply to Re: Odd (to me) case of wrongly guessing context
in thread Odd (to me) case of wrongly guessing context

Note that you can never trigger the right hand side of
( my ($ar) = () ) // die "Undefined array in scalar context";
In other words, you can safely remove the // croak part.
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^3: Odd (to me) case of wrongly guessing context
by LanX (Saint) on May 20, 2013 at 23:32 UTC
    Good catch, but this works

    DB<106> (my ($ar) = () ) || print "bla" bla DB<108> (my ($ar) = (1) ) || print "bla" => 1 DB<109> (my ($ar) = (0) ) || print "bla" => 1 DB<110> (my ($ar) = (undef) )|| print "bla" => 1 DB<111> (my ($ar) = (undef,undef) )|| print "bla" => 2

    list-assignment in scalar context counts and the count is always defined. (see also goatse-operator for comparison.)

    DB<119> scalar ( my ($ar) = () ) => 0

    so only empty-list is 0 and false.

    But I'm not sure if I'm in favour of such constructs...

    Cheers Rolf

    ( addicted to the Perl Programming Language)

Re^3: Odd (to me) case of wrongly guessing context
by rjt (Curate) on May 20, 2013 at 23:29 UTC

    Ah yes, quite right. I missed that in my haste.

    OP, the function you're calling doesn't appear to be standard DBI, so I can't advise you (the OP) on how to handle exceptions, but in general, it will probably be one of the following:

    • The function might die() on error; use eval
    • It may return an empty list, in which case your $mx_registered_process_id will be undef (but undef might also indicate something else, such as a NULL column, so be careful; assign the function return to an intermediary @array if that's the case).
    • It may use a package scalar to hold error values (which is set to undef if there was no error.

    Again, this is all just speculative, since I don't know the semantics of your db_select_row() function.