[sf-perl] Opinions on: next LABEL;

Paul Makepeace Paul.Makepeace at realprogrammers.com
Wed May 11 18:13:23 PDT 2005


Je 2005-05-11 21:22:47 +0100, Bill Moseley skribis:
> On Wed, May 11, 2005 at 11:22:38AM -0700, David Alban wrote:
> > I'm in a situation now where I'd like to:
> > 
> >   FOO:
> >   for ( ... ) {
> > 
> >     for ( ... ) {
> > 
> >        ...some condition... and next FOO;
> > 
> >     } # for
> > 
> >   } # for
> 
> Maybe break it into separate functions?  All that indenting makes it
> hard to code on your cell phone screen, after all.
> 
> sub process_things {
> 
>     process_one_thing( $_ ) for @things;
> 
> }
> 
> sub process_one_thing {
>     my ($thing) = @_;
> 
>     for ( @$thing ) {
> 
>         return if some_condition($_);
> 
>         [do stuff]
>     }
> }

That works in this case but won't work if you wanted last FOO in that
example. You'd have to put in annoying return status checks, or use
exceptions/die+eval. (At least AFAICS at past 2am local time..)

Paul

-- 
Paul Makepeace .............................. http://paulm.com/inchoate/

"If ($_), then you are destined to be disappointed."
   -- http://paulm.com/toys/surrealism/


More information about the SanFrancisco-pm mailing list