Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Thanks all, I'll change it, even if I don't like it as much. I can probably live with one or two more lines of code. I suppose there is a good reason for it throwing a warning at me.. *sigh* :)
It's good practice to never alter the control of a loop externally like that--it makes your subroutine very tightly coupled to that one specific usage, and in fact will blow things up if used differently. Functions should make it easier for you to reuse code in multiple contexts; it's one of their main reasons for existing. Most languages wouldn't even let you put a loop control variable in a sub like that (I know that's not entirely relevant, but just FYI) and Perl is reluctant to do so as well. Other people who may see your code in the future won't be expecting behavior like that.

I think the first reply's solution, using and, is an elegant alternative, and makes it possible to tell what is going on just by looking at the loop code.

My 2 cents!

In reply to Re^3: Exiting subroutine via next (that old chestnut) by nefigah
in thread Exiting subroutine via next (that old chestnut) by why_bird

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?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2023-09-28 18:26 GMT
Find Nodes?
    Voting Booth?

    No recent polls found