in reply to •Re: On Declaration
in thread On Declaration

Yes, the latter is really "Anonymous array containing a list of anonymous hashrefs", but only people like me (and apparently you) would ever be that pedantic.

In the terminology I've always tried to use, that's a "reference to an anonymous array containing references to anonymous hashes." I don't see much wrong with calling it an "anonymous array"; that's a convenient shortcut. But where is the "anonymous hashref"? My understanding of the terms requires the referent¹ to be anonymous, not the reference.

It seems to me that what people so often don't understand is that the value is what is anonymous. Using terminology like "anonymous hashref" just muddies the water, especially when used in the same breath as "anonymous array". You can't be truly pedantic without being consistent too.

1. Of course, the referent could itself be a reference. If I saw my $r = \{ k => 'v' }; I'd say that the scalar variable $r holds a reference to an anonymous reference to an anonymous hash.

-sauoq
"My two cents aren't worth a dime.";

Replies are listed 'Best First'.
Re: Re: •Re: On Declaration
by demerphq (Chancellor) on Jun 16, 2003 at 14:24 UTC

    "reference to an anonymous array containing references to anonymous hashes."

    In a sense the term "anonymous" is irrelevent when you are dealing with a reference to an object. From the point of view of a single statement dealing with a reference to an object every item so contained is anonymous. I would write the above as "a ref to an array of hash references.".


    ---
    demerphq

    <Elian> And I do take a kind of perverse pleasure in having an OO assembly language...
      In a sense the term "anonymous" is irrelevent when you are dealing with a reference to an object.

      In a practical sense maybe, but I think it draws a very important distinction. Even in practice, it is at least somewhat helpful¹.

      From an instructional perspective, I think it is useful to explain the difference between

      my $r1 = [ { foo => 'baz', bar => 'qux' } ];
      . . . and . . .
      my %h = ( foo => 'baz', bar => 'qux' ); my $r2 = [ \%h ];

      I think it is especially useful when you are speaking of an initialization and an anonymous composer because, at that point, you know all of the references to the anonymous data are accounted for. Even in the general case though, saying out loud, "a reference to an anonymous array containing a reference to an anonymous hash" is giving more information than saying "a reference to an anonymous array containing a reference to a hash." The latter makes me want to ask, "which hash?"

      Fixed: Missing closing brace in first bit o' code. Thanks zby.

      Fixed: Yes, I meant %h. Thanks demerphq.

      -sauoq
      "My two cents aren't worth a dime.";
      

        Er, I think you made a mistake in your example. Did you really mean @h? Don't you mean %h?

        Assuming that you mean %h, I personally see no difference. $r2 and $r1 are identical in all respects as far as perl is concerned. And this is my point. my $x=do { \my @anon }; is identical in all useful aspects to my $x=[];. Without using magic there is no way for an external entity to tell if a reference to an array is a reference to a named scalar that is now out of scope or if it is a reference to an array that never had a name. And since there is no way for perl to tell the difference IMO you can only be confusing people when you say a "reference to an anoymous array" in any other curcumstance than saying that the [] symbols (normally) create one.

        you know all of the references to the anonymous data are accounted for.

        Im not sure I understand what you mean here. I dont need to account for anonymous data. Perl does it for me. :-)

        "a reference to an anonymous array containing a reference to an anonymous hash" is giving more information than saying "a reference to an anonymous array containing a reference to a hash."

        My problem with this is that if used your description for the documentation for an argument for a subroutine then somebody might think that is ok to say foo([{}]) but that it not ok to say my (%h,@a); @a=(\%h); foo(\@a). If you leave the issue of anonymous objects to the discussions of how to construct one then no such confusion arises.

        The latter makes me want to ask, "which hash?"

        You already have a reference to it, why do you care what and or if it has a name?

        Let me take this a step further. Why dont you add "lexical" and "dynamic" to your description? After all a lexical array is different from an anonymous dynamic array. (Or is it? IMO its not, but whatever :-). So why not say "a named lexical reference to an anonymous dynamic array containing a reference to a lexical anonymous hash"?

        Bah! Truth be told, id rather say "an arrayref of hashrefs" than any of the above.

        :-)


        ---
        demerphq

        <Elian> And I do take a kind of perverse pleasure in having an OO assembly language...