|more useful options|
logical non-short-circuit operatorsby december (Pilgrim)
|on Nov 02, 2011 at 18:22 UTC||Need Help??|
december has asked for the
wisdom of the Perl Monks concerning the following question:
Hello, fellow monks,
I've got a silly question regarding the use of short-circuit operators in assignments. I want to do something like this (in my code there's actually and instead of or – but I'd like to change it):
The problem is of course that the second assignment isn't executed if the first one succeeds. I'd like both assignments to be executed and only then evaluated so the code in the conditional runs if either one or both of those variables are set. A non-short-circuiting or, so to speak.
I've been looking into using the comma operator for the assignments then re-evaluating the assigned variables with or – all in one long chain, but apparently those variables aren't in scope yet at that point.
Is what I'm doing here silly or am I overlooking a simple logical trick? Is it a bad idea to execute, assign and do logical evaluation in one go?