Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Uninitialized value ?

by mexnix (Pilgrim)
on Aug 20, 2001 at 18:00 UTC ( [id://106230]=note: print w/replies, xml ) Need Help??


in reply to Uninitialized value ?

Try doing this:
#...your code... print "Hello $name,\n "; $secretword = $words{$name} || 'groucho'; #....more code written by you...
what this does is, if the name $name is not in your list, mexnix currently isn't, it automatically assigns "groucho" to $secretword. || is logical OR and you can find it in your perldoc perlop manpage. With this, you can even skip the if ($secretword eq "") { $secretword = "groucho"} stuff, because it already does it for you. My $0.02

__________________________________________________

s mmgfbs nf, nfyojy m,tr yb-zya-zy,s zfzphz,print;
- thanks japhy :)

mexnix.perlmonk.org

Replies are listed 'Best First'.
Re: Re: Uninitialized value ?
by Hofmator (Curate) on Aug 20, 2001 at 18:08 UTC

    and what this also does is bite you back horribly ;-)
    if your $words{$name} evaluates to false, i.e. '' or 0. So better - unless you can outrule those cases: $secretword = defined($words{$name}) ? $words{$name} : 'groucho';

    -- Hofmator

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-03-29 06:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found