Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Default Hash Key

by toolic (Bishop)
on May 02, 2008 at 00:52 UTC ( #684065=note: print w/replies, xml ) Need Help??

in reply to Default Hash Key

Is there a way to define a default value for a hash?
I do not know. But, you could create a function to see if a key exists:
use warnings; use strict; my %description = ( a => 'a vowel', b => 'a consonant' ); print 'a is ', check(\%description, 'a'), "\n"; print 'b is ', check(\%description, 'b'), "\n"; print '~ is ', check(\%description, '~'), "\n"; sub check { my ($href, $key) = @_; return (exists $href->{$key}) ? $href->{$key} : 'not in the alphab +et'; }


a is a vowel b is a consonant ~ is not in the alphabet

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://684065]
LanX fish hawk hunting
[erix]: I think they use Cormorants for that in Asia, by putting a ring around their necks to prevent them from swallowing. Plenty of cormorants here too (=Kormoran)
[erix]: (I've seen gruops of up to a thousand cormorants overhead)

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2017-10-20 10:55 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (261 votes). Check out past polls.