in reply to Hash keys reference

You can't refer to $hash{key} until it exists, and it doesn't exist until that hash creation is done. You'll need to do it separately.

However, you can do something bizarre like this:

my @foo; @foo[0..2] = (10, \$foo[0], 20); print ${ $foo[1] }; # 10
That works, while
my @foo; @foo = (10, \$foo[0], 20); print ${ $foo[1] }; # nothing
does not. ;)

_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a (from-home) job
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Replies are listed 'Best First'.
•Re: Re: Hash keys reference
by merlyn (Sage) on Mar 04, 2002 at 03:22 UTC
    Well, actually, the reference makes it exist. It's the hash assignment that delinks it. Witness the result of:
    %last_name = (); $x = \$last_name{fred}; # creates hash element, value is undef $last_name{fred} = "flintstone"; print $$x; # prints flintstone
    So, your array-slice example would also work on a hash slice:
    undef %last_name; @last_name{qw(fredref fred)} = (\$last_name{fred}, " +flintstone");

    -- Randal L. Schwartz, Perl hacker

      Yes, I'm fully aware of that, which is why I used the example. ;)

      _____________________________________________________
      Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a (from-home) job
      s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;