Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

rjbs (4671)

rjbs
  (email not shown publicly)
http://rjbs.manxome.org/
AOL IM: RicardoJBSignes (Add Buddy, Send Message)
Yahoo! ID: RicardoSignes (Add User, Send Message)

I'm a Perl coder living in Bethlehem, PA and working Philadelphia. I'm a philosopher and theologan by training, but I was shocked to learn upon my graduation that these skills don't have many associated careers. Now I write code.

Journal of rjbs (4671)

Thursday August 18, 2005
11:36 AM

nexting out of loops via sub calls

[ #26354 ]

12:19  * rjbs wants macros in Perl.
12:19 <DrForr> rjbs: Lisp-style? :)
12:19 <rjbs> of course
12:20  * rjbs wants a simple expression that can evaluate to "warn and next"
12:20 <rjbs> (loop-assert cond message)
12:21 <rjbs> which would become (unless (cond) (warn message) (next))
12:22 <DrForr> sub `loop_assert { my ($cond,$warn) = @_; unless($cond) { warn $warn; next } }
12:22 <rjbs> heh
12:24 <rjbs> er... wait...
12:24 <rjbs> that works!?  next will propagate up the call stack?
12:24 <rjbs> how did I not ever know this?
12:24 <DrForr> That's what the ` is for :)
12:24 <rjbs> no, but it seems to do so already
12:25  * rjbs tests more thoroughly.
12:25 <broquaint> Yeah can use loop control in a subroutine but you will get a warning too.
12:26 <rjbs> hell, I'll use "no warnings" for that.

So, yes. If you call a sub inside a loop, and the sub calls next (without the next call being inside an interior loop) the next will propagate up the call stack. There's a warning, but "no warnings 'exiting'" will quash it.

Wow!

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • warn in that Sub will give the sub loop_assert line #

    this macro should use carp (or croak) instead so the message gives the line# of the loop_assert call.

    Assert is an overly strong name for a warning. I'd call it "sub loop_nag" ...
    --
    Bill
    # I had a sig when sigs were cool
    use Sig;
  • This is how skip() is implemented inside Test::More (or possible Test::Builder). I'm sure Schwern wrote about it somewhere...

    -Dom