![]() |
|
Syntactic Confectionery Delight | |
PerlMonks |
Declaring with my, assigning, and testing in same lineby mordibity (Acolyte) |
on Dec 11, 2015 at 14:41 UTC ( [id://1150034]=perlquestion: print w/replies, xml ) | Need Help?? |
mordibity has asked for the wisdom of the Perl Monks concerning the following question: Simplest I think is to just post the canonical example that I run across again and again... I would dearly like this to be all on one line for concision and clarity: This gives:
It's the scoping of the parentheses around the my assignment that causes the problem. If I leave out @v from the error message, the logic is correct and everything works: @v, if assigned to successfully, is correctly set and visible for the print statement. I'm trying to avoid doing work twice (repeating the call to keys in the error message). The ugly alternative is to move my @v outside the comparison, but it just looks clunky and messes up a nice column of assignments. It's not just hash checking, it could be anything:
This has been bugging me for years, and I'm resigned to it, just wondering if there was a clever way around it. Thanks!
Back to
Seekers of Perl Wisdom
|
|