in reply to Re^2: Clarifying the Comma Operator (bareword)
in thread Clarifying the Comma Operator

Actually, that's where the problem lies: 08 is not seen as a string but (wrongly) as an octal number. Perl tries to numify this "word" whereas it should be stringified.
But how should perl know? perl is tokenizing when it encounters the leading 0. Considering that it know it's now expecting a TERM, the leading 0 must mean it's going to encounter an octal number. It doesn't know about the following arrow yet, but it has to decide how to tokenize the next thing.

And that's why all "bare words" look like identifiers. When encountering

foo::bar => baz
perl is expecting a TERM. Barewords can start terms (infix operators like the x tye mentions cannot - that's why infix operators can consist of letters, but prefix operators cannot), and that's why all barewords look like identifiers. Because only after tokenizing the bareword and looking at the next token, perl decides whether the bareword is an identifier (subroutine, filehandle), or a string.

Replies are listed 'Best First'.
Re^4: Clarifying the Comma Operator (bareword)
by CountZero (Bishop) on Jun 07, 2009 at 17:22 UTC
    Perl doesn't know for the very good reasons you quote. But the (partial) sentence I quoted from the docs, gives the impression that the => operator somehow makes a string out of its left-hand argument, which it cannot do anymore as the "octal" error already occurred.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James