Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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>';

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://973768]
help
Chatterbox?
[LanX]: Eily don't be sad ... you are the Bishop of our hearts.
[marto]: 1nickt, I just said that in a Sean Connery accent
[LanX]: Discipulus++ # Bi-Shop
[Eily]: is the Bishop of hearts higher or lower ranked than the Jack?
[ambrus]: Higher.
[Eily]: Discipulus what's the merchandise? Other bi-people?
[1nickt]: marto would like to hear that. Of course he speaks very deliberately and dramatically, allowing pauses between words, so if anybody could pull it off it would be him, or someone impersonating him ...
[Eily]: Discipulus that's a chess joke BTW right? Because bishops don't walk straight :D
[choroba]: stop making chessy jokes about bishops!
[choroba]: I mean cheesy

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (15)
As of 2017-09-26 12:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (294 votes). Check out past polls.

    Notices?