Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

There may be good reason to qualify the seemingly redundant use of the arrow dereferencer between the deepest subscripts. If not solely to understand what is happening in a different way.

...is the same as

${${$VAR1}[0]}{41}

The manner in which dereferencing occurs is different but the result is the same. Most feel the arrow manner is simpler on the brain, being more intuitive once you have grasped the notion of dereferencing.

lets reduce the complexity for a moment

my $VAR2 = [ 101, 201, 42 ]; print $VAR2->[0],' ',${$VAR2}[0]; ------- 101 101

we can now reach the first level reference to the array and by all accounts either syntax is fairly comprehensible.

Lets increase the complexity back up.

my $VAR3 = [ {'101'=>'hel', '201'=>'lo', '42'=>'world'} ]; print $VAR3->[0]->{42},' ',${${$VAR3}[0]}{42}; ------- world world

You can already see the way of the arrow is clearer as the start of the dereference does not accumulate the scalar sigil for each depth of level of complexity. And to be fair this starts literally looking subsequently more expensive too.

The toppler of the cake is that the arrow way also adds the optimisation of saying, hey you know what, seeing as we're already dereferencing here lets not bother making a christmas decoration out of the expression and voila! you get...

print $VAR3->[0]{42}; --- world

Making the array actual, you use dereffing where its needed, not between the first level subscript but between the second level subscript.

my @VAR4 = ( {'101'=>'hel', '201'=>'lo', '42'=>'world'},' dereffed' ); print @VAR4,' ',$VAR4[0]->{42},' ',${$VAR4[0]}{42}; ------- HASH(0x3e81a4) dereffed world world

Comparing the position of the arrow between $VAR3 and $VAR4[0], it would seem this gives us a qualifier for telling us when in a complex structure a 'reference to' or 'an actual' hash/array resides at the first level.

The reason being data structures only hold scalars. The very reason for the requirement of referencing. As a reference to a complex structure is a scalar.

And this of course means the arrow way can safely bah humbug the merry season with all the capacity of your ram.


my $ah={h=>'a'};print %$ah for 0..2;

In reply to Re^3: problem with array of hashes by Don Coyote
in thread problem with array of hashes by Priti24

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    [Corion]: marto: You mean "Sane Dots Dramatic Reading of ITIL" ? ;)
    [marto]: Sane Dots, chapter 13: ITIL never work :P
    [marto]: sorry, bad pun of it'll :P
    [Corion]: :-D
    [Corion]: I think that ITIL is mostly to prevent people from doing harm to a system that basically runs unattended :)
    [Corion]: Maybe you could reduce ITIL to a computer network, a man and a dog. The network runs the computations. The man is there to feed the dog. The dog is there to prevent the man from accessing the computers.
    [marto]: from experience of this side of the fence, it's all about proving to people that you are ITIL compliant, then the client ignores logical processes anyway :P

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (12)
    As of 2017-01-24 10:31 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Do you watch meteor showers?




      Results (203 votes). Check out past polls.