dsb has asked for the wisdom of the Perl Monks concerning the following question:
All bad jokes aside, I was playing around with the trinary operator and was trying to do what I guess you could dynamic variable declaration. For what purpose? I don't know. I just wanted to see if I could do it.
Basically what I was trying to do was:
So whether or not there is an argument to the script would decide which variable, $foo or $bar, would be declared.((shift @ARGV) ? $foo : $bar) = "Hello";
It works fine as is. But if I try to declare with my while using strict, everything falls apart and I get an error.
So I suppose a null operation is one in which no value is returned, which makes sense because why would you use my to declare nothing.use strict; my ((shift @ARGV) ? $foo : $bar) = "Hello"; # Can't declare null operation in "my" at trinary.pl...
So I'm wondering why this is considered a null operation. The trinary should return one value or the other, in the case either $foo or $bar. The only thing I could think of is that b/c strict is in effect, $foo and $bar do not are evaluated before being declared with my and so technically don't exist. But then I wondered why that didn't through a Global symbol error. And besides that, my behaves the same way and throws the same error whether I use strict or not.
Anyway, I'm at a loss. Any ideas?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: my behavior with "NULL" declarations
by dragonchild (Archbishop) on Jul 08, 2004 at 17:44 UTC | |
by ysth (Canon) on Jul 08, 2004 at 17:54 UTC | |
by dsb (Chaplain) on Jul 08, 2004 at 18:11 UTC | |
by dragonchild (Archbishop) on Jul 08, 2004 at 18:18 UTC | |
|
Re: my behavior with "NULL" declarations
by Solo (Deacon) on Jul 08, 2004 at 17:56 UTC | |
|
Re: my behavior with "NULL" declarations
by nightwatch (Scribe) on Jul 08, 2004 at 18:10 UTC |