using 'next' on named loops. 
Author Message
 using 'next' on named loops.

Okay, 2 questions (one easy, the other... ?):

1.  Are these two constructs functionally equivalent:

TEST: {
        print "Hello!\n";
      } continue {
        print "Goodbye!\n";
      }

TEST: { print "Hello!\n"; }
        print "Goodbye!\n";

If you use "next TEST;" somewhere down in a program, they both have
the same effect, right?

2.  Is there any danger in using such a construct as an "error abort"
system in your program?  Say I have a subroutine call in my TEST loop,
and that sub calls other subs, etc, and anywhere in those subs or
sub-subs I get an error that's handled by "next TEST".

Will this lead to any bad memory problems or crashes (it seems to work
so far)?

jas

--
--------------------------------------------------------------------------
Jeffrey A. Sullivan             | Associate Happy Camper




Wed, 30 Mar 1994 05:20:54 GMT  
 using 'next' on named loops.

:Okay, 2 questions (one easy, the other... ?):
:
:1.  Are these two constructs functionally equivalent:
:
:TEST: {
:       print "Hello!\n";
:      } continue {
:       print "Goodbye!\n";
:      }
:
:TEST: { print "Hello!\n"; }
:       print "Goodbye!\n";
:
:If you use "next TEST;" somewhere down in a program, they both have
:the same effect, right?

If it works for you, then yes; empirical sciences and all.

:2.  Is there any danger in using such a construct as an "error abort"
:system in your program?  Say I have a subroutine call in my TEST loop,
:and that sub calls other subs, etc, and anywhere in those subs or
:sub-subs I get an error that's handled by "next TEST".

I get pretty nervous about using loop control on loop in some distant
caller.  I would normally use eval/die instead for setjmp/longjump
or catch/throw functionality.

--tom



Fri, 01 Apr 1994 02:49:33 GMT  
 using 'next' on named loops.

Quote:


>:Okay, 2 questions (one easy, the other... ?):
>:
>:1.  Are these two constructs functionally equivalent:
>:
>:TEST: {
>:   print "Hello!\n";
>:      } continue {
>:   print "Goodbye!\n";
>:      }
>:
>:TEST: { print "Hello!\n"; }
>:   print "Goodbye!\n";
>:
>:If you use "next TEST;" somewhere down in a program, they both have
>:the same effect, right?

>If it works for you, then yes; empirical sciences and all.

>:2.  Is there any danger in using such a construct as an "error abort"
>:system in your program?  Say I have a subroutine call in my TEST loop,
>:and that sub calls other subs, etc, and anywhere in those subs or
>:sub-subs I get an error that's handled by "next TEST".

>I get pretty nervous about using loop control on loop in some distant
>caller.  I would normally use eval/die instead for setjmp/longjump
>or catch/throw functionality.

>--tom

Given that I want to kill only the current step in a loop, could you
give me an example of how you'd use eval/die to implement a
throw/catch type ting?

jas
--
--------------------------------------------------------------------------
Jeffrey A. Sullivan             | Associate Happy Camper




Sat, 02 Apr 1994 05:03:22 GMT  
 using 'next' on named loops.

:>I get pretty nervous about using loop control on loop in some distant
:>caller.  I would normally use eval/die instead for setjmp/longjump
:>or catch/throw functionality.
:
:Given that I want to kill only the current step in a loop, could you
:give me an example of how you'd use eval/die to implement a
:throw/catch type ting?

WHILE_LOOP:
    while ($condition) {
        eval "&function()";



    }

    sub function {
        &another_function;
    }

    sub another_function {
        &yet_another_function;
    }

    sub yet_another_function {
        die "ALL DONE\n" if $something_or_other;
    }

This is going to run a little slower that a last WHILE_LOOP, but
I think that it's worth it.

--tom



Sat, 02 Apr 1994 05:58:30 GMT  
 using 'next' on named loops.
:
: Okay, 2 questions (one easy, the other... ?):
:
: 1.  Are these two constructs functionally equivalent:
:
: TEST: {
:       print "Hello!\n";
:       } continue {
:       print "Goodbye!\n";
:       }
:
: TEST: { print "Hello!\n"; }
:       print "Goodbye!\n";

Well, those two do the same thing, but...

: If you use "next TEST;" somewhere down in a program, they both have
: the same effect, right?

Not necessarily.  This is an infinite loop:

    TEST: {
            print "Hello!\n";
          } continue {
            print "Goodbye!\n";
            next TEST;
          }

And this is a fatal error:

    TEST: {
            print "Hello!\n";
          }
          print "Goodbye!\n";
          next TEST;

: 2.  Is there any danger in using such a construct as an "error abort"
: system in your program?  Say I have a subroutine call in my TEST loop,
: and that sub calls other subs, etc, and anywhere in those subs or
: sub-subs I get an error that's handled by "next TEST".
:
: Will this lead to any bad memory problems or crashes (it seems to work
: so far)?

It happens to work in the current implementation, but I'm not
guaranteeing it to stay that way.  It'd be better to use eval, and do
your "error abort" with a die statement.  Typically you just put a
subroutine call in the eval:

        eval "&realstuff";

This has the additional advantage that you can pass info back as the argument

the disadvantage with "next TEST" that some machines won't let you longjmp()
out of a signal handler.  To be perfectly portable, set a global variable in
the signal handler and check for it periodically outside the signal handler.

Larry



Sat, 02 Apr 1994 07:56:34 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. My Loop Won't Loop

2. next to -n loop in nested loops

3. Using the 'my' option in 'for' loops

4. Help writing 'simple' loop

5. question about 'for' loop functionality

6. value=\"$FORM('name')\" prints 'name' in html

7. problematic regex to match 'first names'

8. '~' in file names

9. XML::Parser and HTML 'named entities'

10. Error: 'document.form.name.Value'

11. 'Use'ing a module whose name is in a scalar

12. readdir() and file named '0'

 

 
Powered by phpBB® Forum Software