in reply to Re^3: my (0?$a:$b): a koan
in thread my (0?$a:$b): a koan
I suspect that it takes any expression, then checks if the expression is valid.Yeah, but even then, it will reject most expressions:
Now, my does return an lvalue, and ?: can, but that isn't enough in itself for it to be accepted by my:$perl -we 'my(f($x))' Can't declare subroutine entry in "my" at -e line 1, at EOF Execution of -e aborted due to compilation errors.
What the reason is that my(my $x) and my(0?$x:$y) are accept isn't clear to me.$ perl -we 'my($x = 3)' Can't declare scalar assignment in "my" at -e line 1, at EOF Execution of -e aborted due to compilation errors.
This one is interesting:
Regardless of the nesting of local and my, we get the same error message.$ perl -we 'my(local $x)' Can't localize lexical variable $x at -e line 1. $ perl -we 'perl -we 'local(my $x)' Can't localize lexical variable $x at -e line 1. $
Mixing state and my:
Mixing our and local:$ perl -wE 'sub f {state (my $x); say ++$x} f; f;' 1 1 $ perl -wE 'sub f {my (state $x); say ++$x} f; f;' 1 2 $ perl -wE 'sub f {state my $x; say ++$x} f; f;' No such class my at -e line 1, near "{state my" Execution of -e aborted due to compilation errors.
So we can have our (local $x), local our $x, but our local $x doesn't parse.$ perl -wE 'sub f {our local $x; say ++$x} f; f;' No such class local at -e line 1, near "{our local" Execution of -e aborted due to compilation errors. $ perl -wE 'sub f {our (local $x); say ++$x} f; f;' 1 1 $ perl -wE 'sub f {local our $x; say ++$x} f; f;' 1 1 $
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: my (0?$a:$b): a koan
by ikegami (Patriarch) on May 05, 2011 at 18:16 UTC | |
by ambrus (Abbot) on May 05, 2011 at 19:24 UTC | |
by mr_mischief (Monsignor) on May 06, 2011 at 06:16 UTC | |
by ikegami (Patriarch) on May 06, 2011 at 06:23 UTC | |
by mr_mischief (Monsignor) on May 06, 2011 at 06:28 UTC |