Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Subroutine question on use of uninitialized value.

by sauoq (Abbot)
on Jun 01, 2012 at 14:08 UTC ( [id://973768]=note: print w/replies, xml ) Need Help??


in reply to Subroutine question on use of uninitialized value.

These two "$args->{zip} and $args->{phone}" will give me warnings on "use of uninitialized value" because I am not passing them.

Actually, that's not true. Perl doesn't care if you pass them or not. You are getting the warnings because you are attempting to use them. It's an important distinction. As has been pointed out, you can use exists(). That'll tell you if the key is in the hash... you might also consider defined(). If you want an empty tag or a default (rather than no tag) when the data doesn't exists, you can use a conditional operator...

print '<zip>' . (defined($args->{zip}) ? $args->{zip} : "DEFAULT") . ' +</zip>';

-sauoq
"My two cents aren't worth a dime.";

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-25 21:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found