--- [EMAIL PROTECTED] wrote:
> Friends -- Could you briefly explain the term "auto-vivification"? I have
> seen this quite a few times in some of the responses.
> 
> A simple example to prove the point would be greatly appreciated.
> 
> Thanks,
> Rex

Rex,

Auto-vivification is trying to access a hash entry that doesn't exit.  If that is 
done, the hash
entry is typically created with an 'undef' value.

my %hash = ( foo => 'bar', baz => 'qux' );

print $hash{ 'foo' }; # prints 'bar'
print $hash{ 'stuff' }; # prints nothing, but now $hash{ 'stuff' } exists and is equal 
to undef

To check for a hash entry without auto-vivifying it, use 'exists'.

if ( exists $hash{ 'stuff" } ) {
    print $hash{ 'stuff' };
} else {
    print q|No %hash entry for 'stuff'.|;
}

Cheers,
Curtis "Ovid" Poe

=====
Senior Programmer
Onsite! Technology (http://www.onsitetech.com/)
"Ovid" on http://www.perlmonks.org/

__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to