Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Subroutine question on use of uninitialized value.

by sauoq (Abbot)
on Jun 01, 2012 at 14:08 UTC ( #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>';

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

Comment on Re: Subroutine question on use of uninitialized value.
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (17)
As of 2015-10-13 14:07 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (307 votes), past polls