hurricup has asked for the wisdom of the Perl Monks concerning the following question:
Hello, Monks!
New parsing question here. This time about % char. Which can be a hash sigil or mod operator
Example:
No prototype in main sub and no prototype in Foo sub (object invocation are ignoring it anyway). Deparse gives me:use strict; package Foo; sub new{return bless {}, 'Foo';} sub mysub{ say "invoked foo->mysub"; } package main; sub mysub{ say "invoked mysub";} my $foo = Foo->new(); $foo->mysub % 2; $foo->mysub %2; mysub % 2; mysub %2;
Object invocation treats % as mod operator. And sub invocation treats as hash sigil. Why so?package Foo; sub new { use strict; return bless({}, 'Foo'); } sub mysub { use strict; print "invoked foo->mysub\n"; } package main; sub mysub { use strict; print "invoked mysub\n"; } use strict; my $foo = 'Foo'->new; $foo->mysub % 2; $foo->mysub % 2; mysub %2; mysub %2;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Ambiguous % parsing
by choroba (Cardinal) on Jul 21, 2015 at 10:15 UTC | |
|
Re: Ambiguous % parsing
by dave_the_m (Monsignor) on Jul 21, 2015 at 10:15 UTC | |
|
Re: Ambiguous % parsing
by Anonymous Monk on Jul 21, 2015 at 10:21 UTC | |
|
Re: Ambiguous % parsing
by hurricup (Pilgrim) on Jul 21, 2015 at 10:31 UTC |