Serveral people have already pointed out why the solution in your last snippet (the my before your if statement) is the best. You should just accept this rather than try for that "more perfect" one liner.
I just wanted to quickly address the confusion about the error message regarding masking the variable. You might think that there will never be a second my declaration for the same variable (thus masking the first declaration) because only one side or the other of the || will be true. If the first condition is true then you're fine; only one declaration is executed. But what does the parser actually do when the first condition is false?
The first my declaration happens, the some_code() assignment happens and only then is it found to be false. Now the parser moves on to the other side of the || and hits a second my declaration. It doesn't somehow forget or throw away what happened before the || just because it didn't turn out to be true.
In reply to Re: creating a variable in an if statement
by Cefu
in thread creating a variable in an if statement
by Tanktalus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |