Hello IvanAK,

And also we have difference between reference and anonymous reference (or not ? but i see a little difference ).

Not really. You will find the built-in function ref useful here. Consider:

#! perl use strict; use warnings; my %hash = ( Fred => 'Wilma', Barney => 'Betty' ); my $ref1 = \%hash; my $ref2 = { Howard => 'Marion', Richie => 'Lori Beth', Chachi => 'Joa +nie' }; printf "\$ref1 is a %s\n", ref $ref1; printf "\$ref2 is a %s\n", ref $ref2;

Output:

0:52 >perl 879_SoPW.pl $ref1 is a HASH $ref2 is a HASH 0:52 >

As you can see, there is no intrinsic difference between the first reference, which is to a named hash, and the second, which is to an anonymous hash. The difference is in the way the hashes are created, not in the references to them.1

My enigma here is what kind of reference or anonymous thing is $sales.

$sales (a scalar variable) contains a reference to a hash. That hash happens to be an anonymous hash, because it was created that way. The values in its key-value pairs also happen to be references to hashes (and, again, those hashes were created anonymously). But that has nothing to do with what $sales is — simply, a reference to a hash.

The “fat comma” operator => has nothing to do with creating references, it is just a convenient replacement for the comma which (1) stringifies the left-hand-side (under certain conditions) and (2) “is helpful in documenting the correspondence between keys and values in hashes, and other paired elements in lists.” — see Comma Operator.

Hope that helps,

1Well, OK, there is an important difference in the reference counts of the hashes: for %hash the reference count is 2, for the anonymous hash referenced by $ref2 it is 1. But that applies to the underlying data structures, not to the reference values held by $ref1 and $ref2.

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Re^2: Hash of Hash by Athanasius
in thread Hash of Hash by IvanAK

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.