LanX has asked for the wisdom of the Perl Monks concerning the following question:
Hi
I was expecting that a prototype sub foo(&) will parse foo {$x} with precedence foo(sub {$x}) but ...
use strict; use warnings; sub foo (&){ } sub bar {} my ($Q,$t) = (10,2); bar ($Q) + bar ($t); foo {$Q} + foo {$t}; # line 12
C:/Strawberry/perl/bin\perl.exe -w d:/tmp/pm/sym.pl Too many arguments for main::foo at d:/tmp/pm/sym.pl line 12, near "}; +" Execution of d:/tmp/pm/sym.pl aborted due to compilation errors.
what is happening here?
Is that a bug or a feature?
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
update: s/d/foo/
update
that's unfortunate, prototypes don't seem to influence precedence at all ... :/
use strict; use warnings; sub bla($) {shift} my ($Q,$t,$res) = (10,2); sub tst { print $res= bla $Q / bla $t; } use B::Deparse; print B::Deparse->new('-p')->coderef2text(\&tst);
C:/Strawberry/perl/bin\perl.exe -w d:/tmp/pm/sym.pl { use warnings; use strict; print(($res = bla(($Q / bla($t))))); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: (SOLVED) parsing problems with prototype blocks (updated)
by haukex (Archbishop) on Nov 03, 2021 at 13:57 UTC | |
by LanX (Saint) on Nov 03, 2021 at 16:44 UTC | |
Re: (SOLVED) parsing problems with prototype blocks (precedence)
by ikegami (Patriarch) on Nov 03, 2021 at 16:09 UTC | |
by LanX (Saint) on Nov 03, 2021 at 16:25 UTC | |
by ikegami (Patriarch) on Nov 04, 2021 at 17:12 UTC |
Back to
Seekers of Perl Wisdom