Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
No, this is not an opportunity for everyone to evaluate my behavior. It's my's behavior that is under the microscope here.

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:

((shift @ARGV) ? $foo : $bar) = "Hello";
So whether or not there is an argument to the script would decide which variable, $foo or $bar, would be declared.

It works fine as is. But if I try to declare with my while using strict, everything falls apart and I get an error.

use strict; my ((shift @ARGV) ? $foo : $bar) = "Hello"; # Can't declare null operation in "my" at trinary.pl...
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.

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?




dsb
This is my cool %SIG

In reply to my behavior with "NULL" declarations by dsb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-25 10:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found