<?xml version="1.0" encoding="windows-1252"?>
<node id="684065" title="Re: Default Hash Key" created="2008-05-01 20:52:23" updated="2008-05-01 16:52:23">
<type id="11">
note</type>
<author id="622051">
toolic</author>
<data>
<field name="doctext">
&lt;blockquote&gt;&lt;i&gt;
Is there a way to define a default value for a hash?&lt;/i&gt;&lt;/blockquote&gt;
I do not know. But, you could create a function to see if a key [doc://exists]:
&lt;c&gt;
use warnings;
use strict;

my %description = (
   a =&gt; 'a vowel',
   b =&gt; '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-&gt;{$key}) ? $href-&gt;{$key} : 'not in the alphabet';
}
&lt;/c&gt;
&lt;p&gt;prints:
&lt;c&gt;
a is a vowel
b is a consonant
~ is not in the alphabet
&lt;/c&gt;</field>
<field name="root_node">
684059</field>
<field name="parent_node">
684059</field>
</data>
</node>
