in reply to Undefined scalar

Hello Nicpetbio23!,

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*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^2: Undefined scalar
by afoken (Chancellor) on Jul 11, 2017 at 17:35 UTC
    print "\$scalar now holds the following value: [", $scalar ? $scalar : 'UNDEF',"]\n";

    It seems a defined has managed to escape from your posting. ;-)

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)