http://qs321.pair.com?node_id=935464

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):

if (my $num = $recFono->field_as_text('102') or my $type = $recFono->f +ield_as_text('104')) { something(); }

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?

Thanks!