I have a copy of Perldoc 5 version 8.8, which is what I use. I couldn't find state in there obviously, because it's an older documentation, and state seems to be a newer feature. But I don't understand why it's working on an older perl.

Because in the code you originally quoted in bold, the v5.10-and-newer state function is not being called. The confusion came because your followon post incorrectly described what you were seeing, and thus the subsequent correct explanation that state can be a built-in function didn't help you understand that specific code correctly. Specifically, you said,

But there's also an equal sign in this line and an arrow -> and a bareword "state"

But you didn't mention that the -> arrow was followed by the bareword "state" in braces . And ->{...} is the Arrow Notation , which even existed in a Perl as ancient as v5.8.

Thus, looking at the code you originally bolded:

goto &{$_[0]->{state} = \&stateReadLit};

The "bareword" state is not an instance of the state function, but rather the key to a hash referenced by the hashref $_[0], so the bareword is interpreted as a string "state", not the function state .

That one line of code is equivalent to the following, which might be more understandable to you:

$_[0]->{state} = \&stateReadLit; # assign the coderef to the stateRea +dLit subroutine to the 'state' element of the hash referenced by $_[0 +] goto &stateReadLit; # or goto &{ $_[0]->{state} };

To sum up: there is no surprise that Perl 5.8 can correctly interpret the bareword state in a hashref arrow-notation syntax construction, just like there is no surprise for $h{state} to refer to the state key of the %h hash.


In reply to Re^5: Weird syntax. What does this goto statement do? by pryrt
in thread Weird syntax. What does this goto statement do? by harangzsolt33

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.