in reply to Re: Re: null keys
in thread null keys

Update: I tried to cancel the submission and ended up in another double submission fiasco. I realied my error, hence the latter post.

--
Steve Marvell

Replies are listed 'Best First'.
Re: Re: Re: Re: null keys
by Juerd (Abbot) on Jun 12, 2002 at 16:37 UTC

    sub bar () { 'quux' } $foo{undef} = 'bareword undef is treated as string'; $foo{+undef} = 'function undef is treated as function because + is not valid in a bareword string'; $foo{bar} = 'key bar is used'; $foo{+bar} = 'key quux is used'; $foo{bar()} = 'key quux is used again (the old value is overwritten)';

    - Yes, I reinvent wheels.
    - Spam: Visit eurotraQ.
    

Re: Re: Re: Re: null keys
by Jenda (Abbot) on Jun 12, 2002 at 16:35 UTC

    If the stuff inside the curlies looks like a word it's automaticaly quoted.

    Thus $hash{undef} and $hash{'undef'} are equivalent.Try :

    $ perl -MO=Deparse -e "print $hash{undef}"

    If you want to use an undef as a hash key you have to use either $hash{+undef} or something like my $NULL = undef; $hash{$NULL}

    Update: Erm ... hash keys are strings. Always. So $hash{+undef} us equivalent to $hash{''}. Oh well.

      Jenda