in reply to Undefined scalar
more ways are possible. You might profit the ternary operator described in perlop too: IF CONDITION ? THEN : ELSE
use strict; use warnings; my $scalar; # starts empty ie undef # IF THEN + ELSE print "\$scalar now holds the following value: [", $scalar ? $scalar : + 'UNDEF',"]\n"; # oops more correct as afoken pointed below: print "\$scalar now holds the following value: [", defined $scalar ? $ +scalar : 'UNDEF',"]\n"; # update: # infact, unless you check with 'defined' a zero can mislead you: $scalar = 0; print "\$scalar now holds the following value: [", $scalar ? $scalar +: 'UNDEF',"]\n"; print "\$scalar now holds the following value: [", defined $scalar ? $ +scalar : 'UNDEF',"]\n";
L*
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Undefined scalar
by afoken (Chancellor) on Jul 11, 2017 at 17:35 UTC |