Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
$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.

In reply to Re: Variables and Scope: The battle begins by tangent
in thread Variables and Scope: The battle begins by Shadow-Master

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (8)
As of 2024-04-24 10:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found