Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Undefined scalar

by Discipulus (Canon)
on Jul 11, 2017 at 16:52 UTC ( [id://1194841]=note: print w/replies, xml ) Need Help??


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". ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1194841]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-25 19:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found