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:

if (uc($quickloop) eq 'LOOP') { LOOP($quickloop, $quicklabel,\$isjmptaken); } ... sub LOOP { my ($quickloop,$quicklabel,$isjmptaken_ref) = @_; $$isjmptaken_ref = 1; }
Note the use of $$ to dereference.

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
    Thank you for the fast reply.
    I think there was a slight misunderstanding in my code. The code that I posted was after I had already made the switch to checking to see if LOOP or JMP was called, then running it. In that code, there is no $jmptaken global variable anymore, it was nixed in favor of an approach that (inefficiently) worked. I am aware that it is set by the value returned in the sub, and I'm happy for it, since it means that the control variable is controlling the loop.
    I did not know about passing it to the sub and was actually looking for a way to pass variable byref instead of byval, so this will be tremendously useful, thank you.
    However in this particular case, it won't be, since to use this technique for this, I would have the worst of both worlds: global variables, and reparsing already parsed input. Until I can get variable scope to work for me without reparsing, I may just stick with what I have.