RE: $p{"Bryan"}{"age"} = 31



Bryan R Harris wrote:
> Is there anything wrong with out of the blue making a statement like
> this:
>
> $p{"Bryan"}{"age"} = 31;

That's fine, as long as $p{Bryan} doesn't exist or is already a hashref.
See: http://c2.com/cgi/wiki?AutoVivification.

For safety, be sure to "use strict" so you don't end up treating $p{Bryan}
as a soft reference:

$p{Bryan} = 'foo';
$p{Bryan}{age} = '31'; # this is like $foo{age} = 31

Also, the quotes are not strictly required.

>
> I thought perl required me to use the anonymous hash composer:
>
> $p{"Bryan"} = { "age" => 31 };

That's fine too, but not exactly equivalent.
.



Relevant Pages

  • Re: sys_wait_h and waitpid
    ... On Mon, 6 Jun 2005, Bryan R Harris wrote: ... Wrap the usestatement in an if block. ... Prev by Date: ...
    (perl.beginners)
  • Re: Use of uninitialized value... --> quit!
    ... > Bryan R Harris wrote: ... based on my understanding of it and what you want it ... Prev by Date: ...
    (perl.beginners)
  • Re: eval without warnings
    ... On Tue, 27 Sep 2005, Bryan R Harris wrote: ... > I'd like to evaluate user input only where it makes sense, ... Prev by Date: ...
    (perl.beginners)
  • Re: Use of uninitialized value... --> quit!
    ... >>Bryan R Harris wrote: ... They are actually warnings instead of errors. ... > ralph 2057% perldoc perllexwarn ...
    (perl.beginners)
  • Re: get function name?
    ... Bryan R Harris wrote: ... I have properties that vary depending on what function I'm in, ... can special-order certain sorts of tools at low cost and ...
    (perl.beginners)