Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Comment on

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

ree:

Just a bit of clarification on RichardK's answer: Notice how it says 'between' subscripts. So after the first one, it's always optional. Before the first one, though, you need to tell perl that you're accessing a value through a reference, and there are two ways you can do so. Either add a '$' to the front, or use a '->' after the scalar:

my @a = ( 1, 4, 9, 16); # squares my @b = ( 1, 8, 27, 64); # cubes my @c = ( \@a, \@b ); # two arrays my $d = \@a; my $e = \@c; # OK: @a is an array print $a[0]; # Wrong: $d is a reference, not an array! print $d[0]; # OK: Both of these are fine, though print $d->[0]; print $$d[0]; # with multiple subscripts: print $e->[0]->[0]; print $e->[0][0]; # same as above, since -> is optional between sub +scripts print $$e[0][0]; # also same as above

You may find yourself preferring an extra '$' at the front (which is what I usually use) or using the '->' (which I use when I want to alert myself to the fact that I'm using a reference). You need to be comfortable with both, since you'll frequently encounter both notations.

Update: D'oh! I bungled my variable declarations, as caught by roho and explained by Athanasius. Corrected (converted square brackets to parenthesis in first three lines).

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re: -> Is Optional ? by roboticus
in thread -> Is Optional ? by vinoth.ree

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!
  • 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?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (14)
    As of 2015-07-07 20:33 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (93 votes), past polls