in reply to Short form (ternary) if else

Or probably
my $vxdg = $vxdgs{$node}{$disk} || "";
thanks

Replies are listed 'Best First'.
Re^2: Short form (ternary) if else
by gg48gg (Sexton) on Feb 09, 2012 at 19:35 UTC
    my $vxdg = $vxdgs{$node}{$disk} || "";
    This is short and sweet, but doesn't take into account a hash value of 0, which could be a valid value. So, if I had a hash value of 0, perl would evaluate it as false, and set the variable to blank.
Re^2: Short form (ternary) if else
by trwww (Priest) on Feb 09, 2012 at 17:38 UTC

    Whenever I see this I usually see this right afterwards:

    if ( $vxdg != '' ) {

    Where they should probably be using:

    if ( $vxdg ) {

    Which would make the || "" in the assignment unnecessary.

    Yes, I understand sometimes zero and the empty string are distinct values from undef in many business rules, but I don't think that applies as aften as many coders believe.