Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

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 chanting in the Monastery: (5)
As of 2015-12-01 01:52 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (791 votes), past polls