in reply to Parsing barewords as sub/method calls?

Well found kind of a workaround:

In the case of arguments for a undeclared bareword putting parens around them is mostly acceptable (syntactically sweet enough)

And without arguments prepending an ampersand helps.

This works w/o messing with strict.

use strict; use warnings; use feature 'say'; our $AUTOLOAD; sub AUTOLOAD { say "Autoload called as $AUTOLOAD(@_)" } BLA(1,2,3); &BLA; no strict 'refs'; #&BLA 1,2,3; __END__ Autoload called as main::BLA(1 2 3) Autoload called as main::BLA()

Cheers Rolf

( addicted to the Perl Programming Language)

update

thanks for pointing out the special meaning of &NAME;, I was aware of it and as Eily pointed out, it's not a problem in this special case.

Replies are listed 'Best First'.
Re^2: Parsing barewords as sub/method calls? (workaround)
by Corion (Patriarch) on Nov 23, 2013 at 17:14 UTC

    Note that &BLA; has the interesting side effect of passing @_ through:

    use strict; use warnings; use feature 'say'; our $AUTOLOAD; sub AUTOLOAD { say "Autoload called as $AUTOLOAD(@_)" } sub BLUBB { say "BLUBB called with @_"; &BLA; }; BLUBB( 1,2,3 );
Re^2: Parsing barewords as sub/method calls? (workaround)
by Eily (Monsignor) on Nov 23, 2013 at 17:21 UTC

    &BLA; is actually equivalent to BLA(@_);. This works in your case because @_ is empty, but if you use this syntax within a sub, you'll forward its arguments.

    use feature 'say'; @_ = qw/4 5 6/; our $AUTOLOAD; sub AUTOLOAD { say "Autoload called as $AUTOLOAD(@_)" } BLA(1,2,3); &BLA; __END__ Autoload called as main::BLA(1 2 3) Autoload called as main::BLA(4 5 6)