in reply to Parse error with subroutines and <

With predeclaration or importing, Perl knows that your bareword is a function call. Without a prototype or parentheses around the argument list, Perl doesn't know its arity. There's no simple way to disambiguate between a <> glob call and your expression.

I recommend using a prototype or parentheses.

Replies are listed 'Best First'.
Re^2: Parse error with subroutines and <
by TedYoung (Deacon) on Dec 14, 2007 at 20:02 UTC
    Good call on the arity! The reason I didn't want to give them a () prototype is because I will find it convenient to call them like:
    $enumClass->$enumName
    sometimes. I was getting ready to respond, it occurred to me that -> notation ignores prototypes! Yay! I get the best of both words. I guess it helps to talk things out!

    Thanks!

    Ted Young

    ($$<<$$=>$$<=>$$<=$$>>$$) always returns 1. :-)

      Just be careful you don't shadow one of your packages with a sub of the same name.

      use strict; use warnings; package Foo; sub bar { print "Foo::bar\n"; } package Bar; sub bar { print "Bar::bar\n"; } package main; sub Foo { "Bar" } Foo->bar(); "Foo"->bar(); exit 0; __END__

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.

      The problem isn't that you're missing the prototype. The problem is that you're missing parens. Omitting parens leads to a lot of problem. Simply put, omitting parens is broken. You must be prepared to add them when necessary.