in reply to Unexpected parser error

You forgot to put the parentheses on the end of function(). Perl started parsing function( / 4; and failed when it ran out of file while parsing the regular expression  4;. You could also have used a prototype on function but those are pretty much always a bad idea.

⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Replies are listed 'Best First'.
Re^2: Unexpected parser error
by saintmike (Vicar) on Feb 22, 2007 at 07:15 UTC
    You forgot to put the parentheses on the end of function().
    No, I didn't.

    That's why I wrote "Sure, function can be disambiguated to function()".

    My point: If 'function' is known as a function name at this point, perl should be smart enough to throw out the possibility that "function / 4" is a regular expression because that's an insane assumption.

      Ok, given that you know perl knows that function is variadic, you know it's going to try to put everything following it into its parameter list. My understanding is that the parser is only able to look ahead one token at a time. The fact that it got two tokens ahead before it found out it couldn't parse things means it just couldn't continue. It isn't capable of backing up from function( / 4; to function() / 4;. You'll just have to provide that information to perl soon enough for the parser to use it. Sorry. Either use the parameter list or set the prototype.

      ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Re^2: Unexpected parser error
by educated_foo (Vicar) on Feb 22, 2007 at 06:21 UTC
    Re prototypes, specifically:
    sub function() { 8 } my $a = f / 4;

      I consider sharing that bit of information a disservice. Prototypes in perl are something to arrive at far into a person's perl experience and generally to skip by. They're good to know about but should almost never be used.

      ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊