in reply to Variables and Scope: The battle begins
$jmptaken would ALWAYS evaluate to the value it was set with, 1 and the loop never stops, 0 and it only runs once, no matter that the debug output always showed it being set in the corresponding subs correctly AND that the value was being passed to the loop conditional correctly.Your code seems to be a confusion of the two approaches you mention. You say that $jmptaken is set 'in' a corresponding sub (approach 2) but from what I can see in your code it is being set by the return value of the sub, i.e. the return value from &LOOP or from &JMP (approach 1). No matter what you set it to 'in' the subs it will always take on the value returned from those subs.
Edit: If you do set $jmptaken in the subs LOOP and JMP, rather than use a global variable you could pass it as a reference to those subs:
Note the use of $$ to dereference.if (uc($quickloop) eq 'LOOP') { LOOP($quickloop, $quicklabel,\$isjmptaken); } ... sub LOOP { my ($quickloop,$quicklabel,$isjmptaken_ref) = @_; $$isjmptaken_ref = 1; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Variables and Scope: The battle begins
by Shadow-Master (Initiate) on Dec 12, 2013 at 16:04 UTC |