[24636] in Perl-Users-Digest
Perl-Users Digest, Issue: 6800 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 3 12:31:45 2004
Date: Tue, 3 Aug 2004 09:30:36 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 3 Aug 2004 Volume: 10 Number: 6800
Today's topics:
Breaking out of nested subroutine? <shah@typhoon.xnet.com>
Re: Breaking out of nested subroutine? <matthew.garrish@sympatico.ca>
Re: Breaking out of nested subroutine? <invalid-email@rochester.rr.com>
Re: Breaking out of nested subroutine? <gnari@simnet.is>
Re: Breaking out of nested subroutine? <gogala@sbcglobal.net>
Re: Breaking out of nested subroutine? <mo.dor@fly.srk.fer.hr>
Re: Breaking out of nested subroutine? (Anno Siegel)
Re: Breaking out of nested subroutine? <nobull@mail.com>
Re: Breaking out of nested subroutine? (Anno Siegel)
Re: Breaking out of nested subroutine? <shah@typhoon.xnet.com>
Re: Breaking out of nested subroutine? <shah@typhoon.xnet.com>
Re: Breaking out of nested subroutine? <musiphil@bawi.org>
Re: Breaking out of nested subroutine? <gogala@sbcglobal.net>
Re: Breaking out of nested subroutine? <nobull@mail.com>
Re: Breaking out of nested subroutine? <gogala@sbcglobal.net>
Re: Breaking out of nested subroutine? 510046470588-0001@t-online.de
Re: Breaking out of nested subroutine? <jgibson@mail.arc.nasa.gov>
Re: Breaking out of nested subroutine? <bik.mido@tiscalinet.it>
Re: Breaking out of nested subroutine? 510046470588-0001@t-online.de
Re: Breaking out of nested subroutine? <gogala@sbcglobal.net>
Re: Breaking out of nested subroutine? <gogala@sbcglobal.net>
Re: Breaking out of nested subroutine? <gogala@sbcglobal.net>
Re: Breaking out of nested subroutine? <abigail@abigail.nl>
Re: Breaking out of nested subroutine? <abigail@abigail.nl>
Re: Breaking out of nested subroutine? <uri@stemsystems.com>
Re: Breaking out of nested subroutine? <perl@my-header.org>
Re: Breaking out of nested subroutine? <bik.mido@tiscalinet.it>
Re: Breaking out of nested subroutine? <gogala@sbcglobal.net>
Re: Breaking out of nested subroutine? <abigail@abigail.nl>
Re: Breaking out of nested subroutine? <bik.mido@tiscalinet.it>
Re: Breaking out of nested subroutine? <sholden@flexal.cs.usyd.edu.au>
Re: Breaking out of nested subroutine? <bik.mido@tiscalinet.it>
Re: Breaking out of nested subroutine? 510046470588-0001@t-online.de
Re: Breaking out of nested subroutine? <matthew.garrish@sympatico.ca>
Re: Breaking out of nested subroutine? <abigail@abigail.nl>
Re: Breaking out of nested subroutine? <bik.mido@tiscalinet.it>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 28 Jul 2004 23:27:19 +0000 (UTC)
From: Hemant Shah <shah@typhoon.xnet.com>
Subject: Breaking out of nested subroutine?
Message-Id: <ce9con$jqo$1@new7.xnet.com>
Folks,
How do I break out from a nested subroutine to the outside of parent
subroutine?
# ----- Module2.pm
sub Function2()
{
sub Function3()
{
If certain condition is met go back to Function1.
How do I return to Function1 from here?
}
Some perl code.
Function3();
More perl code.
}
# ----- Module1.pm
use Module2;
sub Function1()
{
Module2::Function2();
How do I get here from Function3()?
More code.
}
# ----- Main Program
use Module1;
Module1::Function1();
More code.
Thanks.
--
Hemant Shah /"\ ASCII ribbon campaign
E-mail: NoJunkMailshah@xnet.com \ / ---------------------
X against HTML mail
TO REPLY, REMOVE NoJunkMail / \ and postings
FROM MY E-MAIL ADDRESS.
-----------------[DO NOT SEND UNSOLICITED BULK E-MAIL]------------------
I haven't lost my mind, Above opinions are mine only.
it's backed up on tape somewhere. Others can have their own.
------------------------------
Date: Wed, 28 Jul 2004 20:10:10 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Breaking out of nested subroutine?
Message-Id: <AfXNc.14813$BU4.903495@news20.bellglobal.com>
"Hemant Shah" <shah@typhoon.xnet.com> wrote in message
news:ce9con$jqo$1@new7.xnet.com...
>
>
> Folks,
>
> How do I break out from a nested subroutine to the outside of parent
> subroutine?
>
>
> # ----- Module2.pm
> sub Function2()
> {
>
> sub Function3()
> {
> If certain condition is met go back to Function1.
> How do I return to Function1 from here?
> }
>
> Some perl code.
>
> Function3();
>
> More perl code.
> }
>
>
> # ----- Module1.pm
>
> use Module2;
>
> sub Function1()
> {
> Module2::Function2();
>
> How do I get here from Function3()?
>
> More code.
> }
>
>
> # ----- Main Program
>
> use Module1;
>
> Module1::Function1();
>
> More code.
>
Return a value from Function3 indicating whether you should go back to
Function1. As a rather contrived example:
Function1();
sub Function1 {
Function2();
print "Have a good day!\n";
}
sub Function2 {
my ($ok, $retval) = Function3();
return unless $ok;
print "Your lucky number is $retval!\n";
}
sub Function3 {
my $x = sprintf("%2d", rand(1)*100);
if ($x != 13) {
return 1,$x;
}
else {
return 0,0;
}
}
Matt
------------------------------
Date: Thu, 29 Jul 2004 00:42:06 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: Breaking out of nested subroutine?
Message-Id: <41084632.3070306@rochester.rr.com>
Hemant Shah wrote:
...
> How do I break out from a nested subroutine to the outside of parent
> subroutine?
>
>
> # ----- Module2.pm
> sub Function2()
> {
>
> sub Function3()
> {
> If certain condition is met go back to Function1.
> How do I return to Function1 from here?
> }
>
> Some perl code.
>
> Function3();
>
> More perl code.
> }
>
>
> # ----- Module1.pm
>
> use Module2;
>
> sub Function1()
> {
> Module2::Function2();
>
> How do I get here from Function3()?
>
> More code.
> }
>
>
> # ----- Main Program
>
> use Module1;
>
> Module1::Function1();
>
> More code.
Menant, you can put a block around the call to Function2(), and then use
a "last" statement to break out of that block. Like:
# ----- Main Program
use junk479m1;
print "main program\n";
junk479m1::Function1();
#More code.
print "more code in main program\n";
# ----- junk479m1.pm
package junk479m1;
use junk479m2;
sub Function1()
{
print "function1\n";
{junk479m2::Function2();} #note block around the call
#How do I get here from Function3()?
#More code.
print "function1 more code\n";
}
1;
# ----- junk479m2.pm
package junk479m2;
sub Function2()
{
sub Function3()
{
print "function3\n";
#If certain condition is met go back to Function1.
last; #execute this conditionally
#How do I return to Function1 from here?
print "more stuff in function3\n";
}
#Some perl code.
print "function2\n";
Function3();
print "more code in function2\n";
#More perl code.
}
1;
HTH. BTW, your modules were missing the "package" statement and they
did not return a true value as written. Also, the definition of a sub
inside a sub another sub is OK, I guess, but a bit unconventional. I'm
not sure if it compiles it everytime Function2 is executed? If so, that
would be a waste of cycles.
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: Thu, 29 Jul 2004 00:20:19 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: Breaking out of nested subroutine?
Message-Id: <ce9fo6$b4$1@news.simnet.is>
"Hemant Shah" <shah@typhoon.xnet.com> wrote in message
news:ce9con$jqo$1@new7.xnet.com...
>
>
> Folks,
>
> How do I break out from a nested subroutine to the outside of parent
> subroutine?
>
>
> # ----- Module2.pm
> sub Function2()
> {
>
> sub Function3()
> {
> If certain condition is met go back to Function1.
> How do I return to Function1 from here?
return ABORTVALUE if somecondition;
> }
>
> Some perl code.
>
> Function3();
return if Function3() == ABORTVALUE;
>
> More perl code.
> }
gnari
------------------------------
Date: Wed, 28 Jul 2004 21:29:52 -0400
From: Mladen Gogala <gogala@sbcglobal.net>
Subject: Re: Breaking out of nested subroutine?
Message-Id: <pan.2004.07.29.01.29.50.951396@sbcglobal.net>
On Wed, 28 Jul 2004 23:27:19 +0000, Hemant Shah wrote:
>
> Folks,
>
> How do I break out from a nested subroutine to the outside of parent
> subroutine?
What you are asking for, is called a non-local goto in C terminology,
and is considered an extremely bad programming practice. In order to
emulate it, one would have to have a subroutine called main() (where did I
see that before?) set it up as a signal handler for, say, signal 10
(USR1). When one wants to jump back from a subroutine, signal is sent to
itself by using kill function. and you find yourself back in the "main"
function. That was, in essence, the same way it was implemented in C
library. Of course, your perl script would look like this.
#!/usr/bin/perl -w
use strict;
# You need POSIX package to send signal to yourself. It contains
# the getpid() function needed to get your process id.
use POSIX;
use Whatever::else::You::want::to::use;
# Global variables
my ($glob1,$glob2,....,$globn);
main;
sub main {
....
}
Normally, perl programmers have hard time to un-learn things like C,
and master perl idioms. What you are asking for, is a C programming
technique, so you'll have to emulate program structure and behavior
of the C programs, which means going exactly the opposite way then
the most perl programmers usually go.
--
A city is a large community where people are lonesome together.
------------------------------
Date: Thu, 29 Jul 2004 06:33:19 +0000 (UTC)
From: Zeljko Vrba <mo.dor@fly.srk.fer.hr>
Subject: Re: Breaking out of nested subroutine?
Message-Id: <slrncgh6hf.6or.mordor@fly.srk.fer.hr>
On 2004-07-28, Hemant Shah <shah@typhoon.xnet.com> wrote:
>
>
> Folks,
>
> How do I break out from a nested subroutine to the outside of parent
> subroutine?
>
As someone already said, this is nonlocal goto (setjmp/longjmp in C).
In perl you can emulate this with die/eval:
eval {
# call your sub
}
if($@ eq 'something') {
# $@ is return value from die
}
your sub:
sub X {
# whatever
die 34; # this is your return value to innermost eval{}
}
------------------------------
Date: 29 Jul 2004 10:39:12 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Breaking out of nested subroutine?
Message-Id: <ceak4g$ppo$1@mamenchi.zrz.TU-Berlin.DE>
Bob Walton <see@sig.invalid> wrote in comp.lang.perl.misc:
> Hemant Shah wrote:
[...]
> ... Also, the definition of a sub
> inside a sub another sub is OK, I guess, but a bit unconventional. I'm
> not sure if it compiles it everytime Function2 is executed? If so, that
> would be a waste of cycles.
A sub definition is only compiled once, nested or not. What you get is
a named closure (unless you consider that a contradiction in terms).
That is, the inner sub can access lexical variables defined in the
outer one.
Come to think of it, that's another way to abort a call:
sub outer {
# ...
my $abort;
sub inner {
# ...
if ( some_condition() ) {
$abort = 1;
return;
}
# ...
inner( ...);
return if $abort;
# ...
}
However, that's all too tricky for my taste. The straightforward method
is to return something characteristic from the inner call that tells
the outer call not to continue.
Anno
------------------------------
Date: 29 Jul 2004 12:45:53 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Breaking out of nested subroutine?
Message-Id: <u96587yr2m.fsf@wcl-l.bham.ac.uk>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
> Bob Walton <see@sig.invalid> wrote in comp.lang.perl.misc:
> > Hemant Shah wrote:
>
> [...]
>
> > ... Also, the definition of a sub
> > inside a sub another sub is OK, I guess, but a bit unconventional. I'm
> > not sure if it compiles it everytime Function2 is executed? If so, that
> > would be a waste of cycles.
>
> A sub definition is only compiled once, nested or not. What you get is
> a named closure (unless you consider that a contradiction in terms).
It does not behave a proper closure.
> That is, the inner sub can access lexical variables defined in the
> outer one.
But only the first time the outer sub is called.
> Come to think of it, that's another way to abort a call:
>
> sub outer {
> # ...
> my $abort;
> sub inner {
> # ...
> if ( some_condition() ) {
> $abort = 1;
> return;
> }
> # ...
> inner( ...);
> return if $abort;
> # ...
> }
>
> However, that's all too tricky for my taste.
Also it doesn't work after the fist call to outer().
For further explaintion of this, look up the explaintion of the
warning that perl will emit when you compile the above code.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 29 Jul 2004 12:59:46 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Breaking out of nested subroutine?
Message-Id: <ceasc2$pp$1@mamenchi.zrz.TU-Berlin.DE>
Brian McCauley <nobull@mail.com> wrote in comp.lang.perl.misc:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
>
> > Bob Walton <see@sig.invalid> wrote in comp.lang.perl.misc:
> > > Hemant Shah wrote:
> >
> > [...]
> >
> > > ... Also, the definition of a sub
> > > inside a sub another sub is OK, I guess, but a bit unconventional. I'm
> > > not sure if it compiles it everytime Function2 is executed? If so, that
> > > would be a waste of cycles.
> >
> > A sub definition is only compiled once, nested or not. What you get is
> > a named closure (unless you consider that a contradiction in terms).
>
> It does not behave a proper closure.
You're right.
> > That is, the inner sub can access lexical variables defined in the
> > outer one.
>
> But only the first time the outer sub is called.
>
> > Come to think of it, that's another way to abort a call:
> >
> > sub outer {
> > # ...
> > my $abort;
> > sub inner {
> > # ...
> > if ( some_condition() ) {
> > $abort = 1;
> > return;
> > }
> > # ...
> > inner( ...);
> > return if $abort;
> > # ...
> > }
> >
> > However, that's all too tricky for my taste.
>
> Also it doesn't work after the fist call to outer().
>
> For further explaintion of this, look up the explaintion of the
> warning that perl will emit when you compile the above code.
Yeah... missed that too.
Sorry for the sloppy posting.
Anno
------------------------------
Date: Thu, 29 Jul 2004 13:42:02 +0000 (UTC)
From: Hemant Shah <shah@typhoon.xnet.com>
Subject: Re: Breaking out of nested subroutine?
Message-Id: <ceaura$ba4$1@new7.xnet.com>
While stranded on information super highway Bob Walton wrote:
> Hemant Shah wrote:
>
> ...
>> How do I break out from a nested subroutine to the outside of parent
>> subroutine?
>>
>>
>> # ----- Module2.pm
>> sub Function2()
>> {
>>
>> sub Function3()
>> {
>> If certain condition is met go back to Function1.
>> How do I return to Function1 from here?
>> }
>>
>> Some perl code.
>>
>> Function3();
>>
>> More perl code.
>> }
>>
>>
>> # ----- Module1.pm
>>
>> use Module2;
>>
>> sub Function1()
>> {
>> Module2::Function2();
>>
>> How do I get here from Function3()?
>>
>> More code.
>> }
>>
>>
>> # ----- Main Program
>>
>> use Module1;
>>
>> Module1::Function1();
>>
>> More code.
>
>
> Menant, you can put a block around the call to Function2(), and then use
> a "last" statement to break out of that block. Like:
>
> # ----- Main Program
> use junk479m1;
> print "main program\n";
> junk479m1::Function1();
> #More code.
> print "more code in main program\n";
>
>
> # ----- junk479m1.pm
> package junk479m1;
> use junk479m2;
> sub Function1()
> {
> print "function1\n";
> {junk479m2::Function2();} #note block around the call
>
> #How do I get here from Function3()?
> #More code.
> print "function1 more code\n";
> }
> 1;
>
> # ----- junk479m2.pm
> package junk479m2;
> sub Function2()
> {
> sub Function3()
> {
> print "function3\n";
> #If certain condition is met go back to Function1.
> last; #execute this conditionally
> #How do I return to Function1 from here?
> print "more stuff in function3\n";
> }
> #Some perl code.
> print "function2\n";
> Function3();
> print "more code in function2\n";
> #More perl code.
> }
> 1;
>
> HTH. BTW, your modules were missing the "package" statement and they
> did not return a true value as written. Also, the definition of a sub
> inside a sub another sub is OK, I guess, but a bit unconventional. I'm
> not sure if it compiles it everytime Function2 is executed? If so, that
> would be a waste of cycles.
Thanks, I will give that a try. The code I posted was just a small
fragment, so it did not have all the statements from a perl module.
> --
> Bob Walton
> Email: http://bwalton.com/cgi-bin/emailbob.pl
>
--
Hemant Shah /"\ ASCII ribbon campaign
E-mail: NoJunkMailshah@xnet.com \ / ---------------------
X against HTML mail
TO REPLY, REMOVE NoJunkMail / \ and postings
FROM MY E-MAIL ADDRESS.
-----------------[DO NOT SEND UNSOLICITED BULK E-MAIL]------------------
I haven't lost my mind, Above opinions are mine only.
it's backed up on tape somewhere. Others can have their own.
------------------------------
Date: Thu, 29 Jul 2004 13:53:40 +0000 (UTC)
From: Hemant Shah <shah@typhoon.xnet.com>
Subject: Re: Breaking out of nested subroutine?
Message-Id: <ceavh4$c96$1@new7.xnet.com>
Folks,
Thanks for all the different ways to break out of a nested subroutine
I will give them a try and see which works.
There may be a simpler way in the module I am using.
I am using XML::PARSER to parse an xml file and have define handlers for
Start, End, and Char. I want to stop processing, when I encounter a
particular tag (i.e. break out of Start handler and stop further processing
of XML file).
--
Hemant Shah /"\ ASCII ribbon campaign
E-mail: NoJunkMailshah@xnet.com \ / ---------------------
X against HTML mail
TO REPLY, REMOVE NoJunkMail / \ and postings
FROM MY E-MAIL ADDRESS.
-----------------[DO NOT SEND UNSOLICITED BULK E-MAIL]------------------
I haven't lost my mind, Above opinions are mine only.
it's backed up on tape somewhere. Others can have their own.
------------------------------
Date: Thu, 29 Jul 2004 13:14:53 -0700
From: Seungbeom Kim <musiphil@bawi.org>
Subject: Re: Breaking out of nested subroutine?
Message-Id: <ceblru$obr$1@news.Stanford.EDU>
Mladen Gogala wrote:
> On Wed, 28 Jul 2004 23:27:19 +0000, Hemant Shah wrote:
>
>> How do I break out from a nested subroutine to the outside of parent
>> subroutine?
>
> What you are asking for, is called a non-local goto in C terminology,
> and is considered an extremely bad programming practice.
You can't generalise like that. Those situations happen quite frequently,
and they're what exception handling in C++, Java, etc. is designed for.
--
Seungbeom Kim
------------------------------
Date: Thu, 29 Jul 2004 17:13:55 -0400
From: Mladen Gogala <gogala@sbcglobal.net>
Subject: Re: Breaking out of nested subroutine?
Message-Id: <pan.2004.07.29.21.13.54.507696@sbcglobal.net>
On Thu, 29 Jul 2004 13:14:53 -0700, Seungbeom Kim wrote:
> You can't generalise like that. Those situations happen quite
> frequently, and they're what exception handling in C++, Java, etc. is
> designed for.
Exception handling is not the same as longjmp. Exception handling is an OO
technique in which objects "throw error objects" (unfortunately, English
betrays us here) which are then "caught" in exception handlers. Non-local
goto or long jump is also a technique based on system trap, but without
any handlers, just a context switch. The expression "break out of
subroutine" is more reminiscent of longjmp then of the throw-catch
mechanism, at least in my opinion. You'll note that, in contrast to C,
perl doesn't have "goto" command, which was deemed bad by Mr. Dijsktra in
his historic paper called "Modular Programming", published in the middle
of the last century. From the point of view of modular programming, any
goto is a bad thing. Non-local goto is a very bad thing, I'm afraid.
--
A city is a large community where people are lonesome together.
------------------------------
Date: 29 Jul 2004 23:04:00 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Breaking out of nested subroutine?
Message-Id: <u9u0vq1ne7.fsf@wcl-l.bham.ac.uk>
Mladen Gogala <gogala@sbcglobal.net> writes:
> On Thu, 29 Jul 2004 13:14:53 -0700, Seungbeom Kim wrote:
>
> > You can't generalise like that. Those situations happen quite
> > frequently, and they're what exception handling in C++, Java, etc. is
> > designed for.
>
> Exception handling is not the same as longjmp. Exception handling is an OO
> technique in which objects "throw error objects" (unfortunately, English
> betrays us here) which are then "caught" in exception handlers. Non-local
> goto or long jump is also a technique based on system trap, but without
> any handlers, just a context switch. The expression "break out of
> subroutine" is more reminiscent of longjmp then of the throw-catch
> mechanism,
Doesn't seem to inply one mechanism over the other to me.
> at least in my opinion.
Throw-catch is just a more elegant way to do what longjmp achieved in
a rather quick and dirty fashion. In Perl (and other modern
languages) when you break out of deep stack frame t unwinds the stack
giving each stack frame a chance to clean up after itself.
> You'll note that, in contrast to C, perl doesn't have "goto"
> command,
Errr...?
> which was deemed bad by Mr. Dijsktra in
> his historic paper called "Modular Programming", published in the middle
> of the last century. From the point of view of modular programming, any
> goto is a bad thing.
Be aware that not only is Perl's goto() a goto but so too are
return(), next(), last() and especially redo().
Use the best tool for the job. Do not let just reject it because it
has been "deemed bad".
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 29 Jul 2004 18:55:35 -0400
From: Mladen Gogala <gogala@sbcglobal.net>
Subject: Re: Breaking out of nested subroutine?
Message-Id: <pan.2004.07.29.22.55.34.243006@sbcglobal.net>
On Thu, 29 Jul 2004 23:04:00 +0100, Brian McCauley wrote:
> Errr...?
You are right. I've never used it, and I didn't even know it existed.
>
>> which was deemed bad by Mr. Dijsktra in
>> his historic paper called "Modular Programming", published in the middle
>> of the last century. From the point of view of modular programming, any
>> goto is a bad thing.
>
> Be aware that not only is Perl's goto() a goto but so too are
> return(), next(), last() and especially redo().
Next is an equivalent to "continue", last is an equivalent to "break".
C doesn't have anything like "redo". Why do you think those are goto's?
When you translate them to assembly language, they all do include JMP
command, but they're not equivalent to the goto command in its classic
sense.
>
> Use the best tool for the job. Do not let just reject it because it
> has been "deemed bad".
Modular programming dictates you to break program in subroutines and
functions where it makes sense, instead of writing monolithic monsters
having 10,000+ lines of code in a single program unit. When you have
subs, goto just doesn't look like The Right Way (TM) to control the
program flow. Of course, it is all highly subjective. The important
thing for programs is to work and to be easy to maintain. If you can
achieve that with a goto or two, good for you.
--
A city is a large community where people are lonesome together.
------------------------------
Date: 29 Jul 2004 22:28:07 +0200
From: 510046470588-0001@t-online.de
Subject: Re: Breaking out of nested subroutine?
Message-Id: <87d62e36eg.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me>
Seungbeom Kim <musiphil@bawi.org> writes:
> Mladen Gogala wrote:
>
> > On Wed, 28 Jul 2004 23:27:19 +0000, Hemant Shah wrote:
> >
> >> How do I break out from a nested subroutine to the outside of parent
> >> subroutine?
> > What you are asking for, is called a non-local goto in C terminology,
> > and is considered an extremely bad programming practice.
>
> You can't generalise like that. Those situations happen quite
> frequently, and they're what exception handling in C++, Java, etc. is
> designed for.
>
Scheme is much better off, as it has call-with-current-continuation
which even allows to resume subroutines later on.
Klaus Schilling
------------------------------
Date: Fri, 30 Jul 2004 11:45:51 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Breaking out of nested subroutine?
Message-Id: <300720041145511659%jgibson@mail.arc.nasa.gov>
In article <pan.2004.07.29.21.13.54.507696@sbcglobal.net>, Mladen
Gogala <gogala@sbcglobal.net> wrote:
> On Thu, 29 Jul 2004 13:14:53 -0700, Seungbeom Kim wrote:
>
>
> > You can't generalise like that. Those situations happen quite
> > frequently, and they're what exception handling in C++, Java, etc. is
> > designed for.
>
> Exception handling is not the same as longjmp. Exception handling is an OO
> technique in which objects "throw error objects" (unfortunately, English
> betrays us here) which are then "caught" in exception handlers.
Sorry to disagree, but I don't think exception handling is an
object-oriented concept. I first encountered exceptions in Ada 83,
which was specified in 1980 and was undoubtedly borrowing from earlier
languages. Exceptions work just fine with procedural languages.
> Non-local
> goto or long jump is also a technique based on system trap, but without
> any handlers, just a context switch. The expression "break out of
> subroutine" is more reminiscent of longjmp then of the throw-catch
> mechanism, at least in my opinion. You'll note that, in contrast to C,
> perl doesn't have "goto" command, which was deemed bad by Mr. Dijsktra in
> his historic paper called "Modular Programming", published in the middle
> of the last century. From the point of view of modular programming, any
> goto is a bad thing. Non-local goto is a very bad thing, I'm afraid.
perldoc -f goto
I believe the paper was called "Go to statement considered harmful"
(Communications of the ACM 11, 147-148, 1968), available at
http://www.acm.org/classics/oct95/
------------------------------
Date: Sat, 31 Jul 2004 13:09:07 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Breaking out of nested subroutine?
Message-Id: <6mpmg0tevlb7s07unen8r86v2m0gtbgc84@4ax.com>
On Thu, 29 Jul 2004 17:13:55 -0400, Mladen Gogala
<gogala@sbcglobal.net> wrote:
>mechanism, at least in my opinion. You'll note that, in contrast to C,
>perl doesn't have "goto" command, which was deemed bad by Mr. Dijsktra in
perldoc -f goto
?
Michele
--
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
"perl bug File::Basename and Perl's nature"
------------------------------
Date: 31 Jul 2004 10:28:37 +0200
From: 510046470588-0001@t-online.de
Subject: Re: Breaking out of nested subroutine?
Message-Id: <87n01gbmx6.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me>
Jim Gibson <jgibson@mail.arc.nasa.gov> writes:
> In article <pan.2004.07.29.21.13.54.507696@sbcglobal.net>, Mladen
> Gogala <gogala@sbcglobal.net> wrote:
>
> > On Thu, 29 Jul 2004 13:14:53 -0700, Seungbeom Kim wrote:
> >
> >
> > > You can't generalise like that. Those situations happen quite
> > > frequently, and they're what exception handling in C++, Java, etc. is
> > > designed for.
> >
> > Exception handling is not the same as longjmp. Exception handling is an OO
> > technique in which objects "throw error objects" (unfortunately, English
> > betrays us here) which are then "caught" in exception handlers.
>
> Sorry to disagree, but I don't think exception handling is an
> object-oriented concept. I first encountered exceptions in Ada 83,
> which was specified in 1980 and was undoubtedly borrowing from earlier
> languages. Exceptions work just fine with procedural languages.
>
and emacs lisp has exception handling, being utterly distant from OO,
so there's absolutely no correlation between OO and exception handling.
> > Non-local
> > goto or long jump is also a technique based on system trap, but without
> > any handlers, just a context switch. The expression "break out of
> > subroutine" is more reminiscent of longjmp then of the throw-catch
> > mechanism, at least in my opinion. You'll note that, in contrast to C,
> > perl doesn't have "goto" command, which was deemed bad by Mr. Dijsktra in
> > his historic paper called "Modular Programming", published in the middle
> > of the last century. From the point of view of modular programming, any
> > goto is a bad thing. Non-local goto is a very bad thing, I'm afraid.
I don't care the slightest little bit what right-wing fundamentalists
consider as a very bad thing.
call-with-current-continuation rocks all the way.
>
> perldoc -f goto
>
> I believe the paper was called "Go to statement considered harmful"
> (Communications of the ACM 11, 147-148, 1968), available at
> http://www.acm.org/classics/oct95/
harmful for the ego of those who want to tyrannise others and enforce
their own coding style upon them.
Klaus Schilling
------------------------------
Date: Sat, 31 Jul 2004 13:46:24 -0400
From: Mladen Gogala <gogala@sbcglobal.net>
Subject: Re: Breaking out of nested subroutine?
Message-Id: <pan.2004.07.31.17.46.24.143370@sbcglobal.net>
On Fri, 30 Jul 2004 11:45:51 -0700, Jim Gibson wrote:
> I believe the paper was called "Go to statement considered harmful"
> (Communications of the ACM 11, 147-148, 1968), available at
> http://www.acm.org/classics/oct95/
Thanks for correction and source.
--
A city is a large community where people are lonesome together.
------------------------------
Date: Sat, 31 Jul 2004 13:54:44 -0400
From: Mladen Gogala <gogala@sbcglobal.net>
Subject: Re: Breaking out of nested subroutine?
Message-Id: <pan.2004.07.31.17.54.44.141736@sbcglobal.net>
On Sat, 31 Jul 2004 13:09:07 +0200, Michele Dondi wrote:
>
>>mechanism, at least in my opinion. You'll note that, in contrast to C,
>>perl doesn't have "goto" command, which was deemed bad by Mr. Dijsktra in
>
> perldoc -f goto
> ?
As I've said before, I've never seen it used and I've never used it,
so I didn't know that it still existed. If you structure your programs
appropriately, there will be no need for goto statements. That's what "sub"
is for.
--
A city is a large community where people are lonesome together.
------------------------------
Date: Sat, 31 Jul 2004 13:56:32 -0400
From: Mladen Gogala <gogala@sbcglobal.net>
Subject: Re: Breaking out of nested subroutine?
Message-Id: <pan.2004.07.31.17.56.32.981984@sbcglobal.net>
On Sat, 31 Jul 2004 10:28:37 +0200, 510046470588-0001 wrote:
> I don't care the slightest little bit what right-wing fundamentalists
> consider as a very bad thing.
> call-with-current-continuation rocks all the way.
We protect the Earth from the scum of the Universe.
--
A city is a large community where people are lonesome together.
------------------------------
Date: 31 Jul 2004 23:21:47 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Breaking out of nested subroutine?
Message-Id: <slrncgoacb.6hs.abigail@alexandra.abigail.nl>
Mladen Gogala (gogala@sbcglobal.net) wrote on MMMCMLXXXVII September
MCMXCIII in <URL:news:pan.2004.07.31.17.54.44.141736@sbcglobal.net>:
// On Sat, 31 Jul 2004 13:09:07 +0200, Michele Dondi wrote:
//
// >
// >>mechanism, at least in my opinion. You'll note that, in contrast to C,
// >>perl doesn't have "goto" command, which was deemed bad by Mr. Dijsktra in
// >
// > perldoc -f goto
// > ?
//
// As I've said before, I've never seen it used and I've never used it,
// so I didn't know that it still existed. If you structure your programs
// appropriately, there will be no need for goto statements. That's what "sub"
// is for.
Well, I find 'goto' in C programs quite handy. In Perl too, except I
usually spell 'goto' as 'redo', 'next' or 'last'.
BTW, I've no doubt that Mr. Dijkstra would have the same dim opinion about
Perl as a language as he had for 'goto' as a statement.
Abigail
--
perl -MLWP::UserAgent -MHTML::TreeBuilder -MHTML::FormatText -wle'print +(
HTML::FormatText -> new -> format (HTML::TreeBuilder -> new -> parse (
LWP::UserAgent -> new -> request (HTTP::Request -> new ("GET",
"http://work.ucsd.edu:5141/cgi-bin/http_webster?isindex=perl")) -> content))
=~ /(.*\))[-\s]+Addition/s) [0]'
------------------------------
Date: 31 Jul 2004 23:38:01 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Breaking out of nested subroutine?
Message-Id: <slrncgobap.6hs.abigail@alexandra.abigail.nl>
Mladen Gogala (gogala@sbcglobal.net) wrote on MMMCMLXXXV September
MCMXCIII in <URL:news:pan.2004.07.29.21.13.54.507696@sbcglobal.net>:
** On Thu, 29 Jul 2004 13:14:53 -0700, Seungbeom Kim wrote:
**
**
** > You can't generalise like that. Those situations happen quite
** > frequently, and they're what exception handling in C++, Java, etc. is
** > designed for.
**
** Exception handling is not the same as longjmp. Exception handling is an OO
** technique in which objects "throw error objects" (unfortunately, English
** betrays us here) which are then "caught" in exception handlers. Non-local
** goto or long jump is also a technique based on system trap, but without
** any handlers, just a context switch. The expression "break out of
** subroutine" is more reminiscent of longjmp then of the throw-catch
** mechanism, at least in my opinion. You'll note that, in contrast to C,
** perl doesn't have "goto" command, which was deemed bad by Mr. Dijsktra in
** his historic paper called "Modular Programming", published in the middle
** of the last century. From the point of view of modular programming, any
** goto is a bad thing. Non-local goto is a very bad thing, I'm afraid.
A few things:
- Perl does have a 'goto' statement. In fact, it has three goto statements,
and three statements who, while they aren't spelled 'goto', aren't very
different from a 'goto'. ('last', 'next' and 'redo').
- The paper you are referring to is:
Edsger W. Dijkstra: "Go To Statement Considered Harmful"
However, the title isn't his. The title he put on the paper he submitted
to the CACM was "A case against the GOTO statement"; the editor, Niklaus
Wirth, changed the title.
- There's another famous computer scientist, who, unlike EWD, gives the
impression of actually having used a computer more than once in his life.
He also wrote a paper. The paper I refer to:
Donald E. Knuth: "Structured Programming with goto Statements"
I prefer this 72 page discussion of goto's pro and cons over the 2.5 page
emotional pamphlet of EWD. Heck, DEK's reference list is longer than EWDs
entire paper.
Abigail
--
perl -Mstrict='}); print "Just another Perl Hacker"; ({' -le1
------------------------------
Date: Sun, 01 Aug 2004 04:13:39 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Breaking out of nested subroutine?
Message-Id: <x7pt6bcx7h.fsf@mail.sysarch.com>
>>>>> "A" == Abigail <abigail@abigail.nl> writes:
A> Well, I find 'goto' in C programs quite handy. In Perl too, except I
A> usually spell 'goto' as 'redo', 'next' or 'last'.
A> BTW, I've no doubt that Mr. Dijkstra would have the same dim
A> opinion about Perl as a language as he had for 'goto' as a
A> statement.
heh, i agree. we all want those fun state variables in each nested loop
and checking for them at each level. GAHHH!!!!
and to the OP, magic goto is very useful but has little to do with
classic goto. larry had a bad habit of overloading function names (eval,
select, goto).
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Sun, 01 Aug 2004 14:53:59 +0200
From: Matija Papec <perl@my-header.org>
Subject: Re: Breaking out of nested subroutine?
Message-Id: <ruppg0hmvqfkogq2cmvb8edjogqhkqqou3@4ax.com>
X-Ftn-To: Abigail
Abigail <abigail@abigail.nl> wrote:
>A few things:
>
>- Perl does have a 'goto' statement. In fact, it has three goto statements,
> and three statements who, while they aren't spelled 'goto', aren't very
> different from a 'goto'. ('last', 'next' and 'redo').
But they are different, and they differ in significant way; at least when
analyzing code from algorithm perspective.
>- The paper you are referring to is:
> Edsger W. Dijkstra: "Go To Statement Considered Harmful"
> However, the title isn't his. The title he put on the paper he submitted
> to the CACM was "A case against the GOTO statement"; the editor, Niklaus
> Wirth, changed the title.
>- There's another famous computer scientist, who, unlike EWD, gives the
> impression of actually having used a computer more than once in his life.
> He also wrote a paper. The paper I refer to:
> Donald E. Knuth: "Structured Programming with goto Statements"
> I prefer this 72 page discussion of goto's pro and cons over the 2.5 page
> emotional pamphlet of EWD. Heck, DEK's reference list is longer than EWDs
> entire paper.
IMO, using goto is like swearing. There are people that never swear, even
when they should, and so they cut themselves from clear and straight to the
point way of expression (at least in some specific situations). On the other
hand, Dijkstra IMHO had some hard time with poor programmers which were
swearing all the time, so he came to idea to take away "goto" freedom from
them so their work could become more readable. It all depends to whom are
you applying the rules which brings us to familiar cons. and pros. for
freedom/strict environment.
--
Matija
------------------------------
Date: Sun, 01 Aug 2004 20:16:06 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Breaking out of nested subroutine?
Message-Id: <gs9pg05qeptinccimncritp1cgbbu6ro98@4ax.com>
On Thu, 29 Jul 2004 18:55:35 -0400, Mladen Gogala
<gogala@sbcglobal.net> wrote:
[about goto()]
>> Errr...?
>
>You are right. I've never used it, and I didn't even know it existed.
Not only does it exist, but it also allow an &-form which is not
really a goto in the sense you were talking about:
[admittedly stupid example]
#!/usr/bin/perl -l
use strict;
use warnings;
sub doit;
doit $_, qw/foo bar baz/ for 0..2;
sub doit () {
my $i=shift;
print "Operation <$i>:";
goto ( sub { print for @_ },
sub { print scalar @_ },
sub { print "@_" } )[$i];
}
__END__
Michele
--
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
"perl bug File::Basename and Perl's nature"
------------------------------
Date: Sun, 01 Aug 2004 17:41:33 -0400
From: Mladen Gogala <gogala@sbcglobal.net>
Subject: Re: Breaking out of nested subroutine?
Message-Id: <pan.2004.08.01.21.41.32.669513@sbcglobal.net>
On Sat, 31 Jul 2004 23:21:47 +0000, Abigail wrote:
> Well, I find 'goto' in C programs quite handy. In Perl too, except I
> usually spell 'goto' as 'redo', 'next' or 'last'.
It's not the same thing. The "C" equivalent of "next" is "continue",
equivalent of "last" is "break", while C doesn't have an equivalent of
"redo". If the command exists, you are welcome to use it, but I want to be
the one who would maintain your programs, if you make an extensive use of
the "goto" command. Modular programming languages are usually accompanied
by certain kind of aesthetics which regards the use of "goto" statement as
"ugly". This is not a liberty issue, this is aesthetics. It's exactly the
same thing as putting a bra on the goddess of justice, or putting a
loincloth on a replica of Michelangelo's "David": doable, but silly.
--
A city is a large community where people are lonesome together.
------------------------------
Date: 01 Aug 2004 22:23:44 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Breaking out of nested subroutine?
Message-Id: <slrncgqrbg.6hs.abigail@alexandra.abigail.nl>
Mladen Gogala (gogala@sbcglobal.net) wrote on MMMCMLXXXVIII September
MCMXCIII in <URL:news:pan.2004.08.01.21.41.32.669513@sbcglobal.net>:
** On Sat, 31 Jul 2004 23:21:47 +0000, Abigail wrote:
**
** > Well, I find 'goto' in C programs quite handy. In Perl too, except I
** > usually spell 'goto' as 'redo', 'next' or 'last'.
**
** It's not the same thing. The "C" equivalent of "next" is "continue",
** equivalent of "last" is "break", while C doesn't have an equivalent of
** "redo".
I never claimed otherwise. I use 'goto' in C programs. I use 'next', 'last',
and 'redo' in Perl programs. That's what I said. How you turn that into
me claiming that C has 'next', 'last', or 'redo', I don't know.
** If the command exists, you are welcome to use it, but I want to be
** the one who would maintain your programs, if you make an extensive use of
** the "goto" command. Modular programming languages are usually accompanied
** by certain kind of aesthetics which regards the use of "goto" statement as
** "ugly". This is not a liberty issue, this is aesthetics. It's exactly the
** same thing as putting a bra on the goddess of justice, or putting a
** loincloth on a replica of Michelangelo's "David": doable, but silly.
I've no problem writing (in C):
__close:
if (close (fd) == -1) {
if (errno == EINTR) {
goto __close;
}
perror ("close");
exit (1);
}
IMO, that's cleaner than introducing some extra variable and an extra loop.
And in Perl, I would write the equivalent using a bare block and a 'redo'
statement, if close() wouldn't automatically restart after an interrupt.
Abigail
--
perl -wlpe '}{$_=$.}{' file # Count the number of lines.
------------------------------
Date: Mon, 02 Aug 2004 00:52:03 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Breaking out of nested subroutine?
Message-Id: <mkqqg0hr9mcumjqrh0nuueila3nielef3h@4ax.com>
On Sat, 31 Jul 2004 13:54:44 -0400, Mladen Gogala
<gogala@sbcglobal.net> wrote:
>>>mechanism, at least in my opinion. You'll note that, in contrast to C,
>>>perl doesn't have "goto" command, which was deemed bad by Mr. Dijsktra in
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>> perldoc -f goto
>> ?
>
>As I've said before, I've never seen it used and I've never used it,
>so I didn't know that it still existed. If you structure your programs
>appropriately, there will be no need for goto statements. That's what "sub"
>is for.
I'm not contending this, nay: I *do* agree with you. Though perl
indeed has a C<goto>. Hence my cmt, period.
More precisely it is true that perl has some flavours of C<goto> in
disguise that blend nicely in the syntax of the language, but a "true"
C<goto> disregarding matters of wether it is considered harmful or
not, is first of all aesthetically unpleasant.
FWIW I did know it existed but have never felt the need of using it
but in one case in which it was the lightest solution to provide some
code with an "extra feature" it had not been thought for in the first
place. Can't even remember what it was about, but remember full well
that I did insert that line half-heartedly and almost feeling guilty!
;-)
Also, as I wrote in another post in this thread there's also a special
form of C<goto> that is useful in certain situations, especially in OO
programming.
Michele
--
>It's because the universe was programmed in C++.
No, no, it was programmed in Forth. See Genesis 1:12:
"And the earth brought Forth ..."
- Robert Israel on sci.math, thread "Why numbers?"
------------------------------
Date: 1 Aug 2004 23:42:09 GMT
From: Sam Holden <sholden@flexal.cs.usyd.edu.au>
Subject: Re: Breaking out of nested subroutine?
Message-Id: <slrncgqvuh.vgs.sholden@flexal.cs.usyd.edu.au>
On 01 Aug 2004 22:23:44 GMT, Abigail <abigail@abigail.nl> wrote:
>
> I've no problem writing (in C):
>
> __close:
> if (close (fd) == -1) {
> if (errno == EINTR) {
> goto __close;
> }
> perror ("close");
> exit (1);
> }
>
>
> IMO, that's cleaner than introducing some extra variable and an extra loop.
while (close (fd) == -1) {
if (errno != EINTR) {
perror ("close");
exit (1);
}
}
Of course the if body could also be used with the goto replaced with
continue. The while loop, to me anyway, expressed what I'm trying to
do more clearly - keep trying to close fd if it fails temporarily.
But as always TIMTOWTDI.
I do use gotos in other situations though, the most obvious example
I can think of being when implementing a state machine.
--
Sam Holden
------------------------------
Date: Mon, 02 Aug 2004 12:02:56 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Breaking out of nested subroutine?
Message-Id: <vq3sg0dco87o7aopvviph4mcop26654ud9@4ax.com>
On Sun, 01 Aug 2004 17:41:33 -0400, Mladen Gogala
<gogala@sbcglobal.net> wrote:
>On Sat, 31 Jul 2004 23:21:47 +0000, Abigail wrote:
>
>> Well, I find 'goto' in C programs quite handy. In Perl too, except I
>> usually spell 'goto' as 'redo', 'next' or 'last'.
>
>It's not the same thing. The "C" equivalent of "next" is "continue",
>equivalent of "last" is "break", while C doesn't have an equivalent of
>"redo". If the command exists, you are welcome to use it, but I want to be
>the one who would maintain your programs, if you make an extensive use of
>the "goto" command. Modular programming languages are usually accompanied
>by certain kind of aesthetics which regards the use of "goto" statement as
>"ugly". This is not a liberty issue, this is aesthetics. It's exactly the
>same thing as putting a bra on the goddess of justice, or putting a
>loincloth on a replica of Michelangelo's "David": doable, but silly.
I think that there's some misunderstanding going on here. I think we
all agree at least to a high degree with all these points. All that
Abigail was saying, wittily as usual, is that C<redo>, C<next> and
C<last> are sorts of goto's (albeit aesthetically more acceptable, *I*
say) and that indeed they are quite useful in Perl.
Michele
--
# This prints: Just another Perl hacker,
seek DATA,15,0 and print q... <DATA>;
__END__
------------------------------
Date: 02 Aug 2004 07:58:23 +0200
From: 510046470588-0001@t-online.de
Subject: Re: Breaking out of nested subroutine?
Message-Id: <87brhu84jk.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me>
Michele Dondi <bik.mido@tiscalinet.it> writes:
> More precisely it is true that perl has some flavours of C<goto> in
> disguise that blend nicely in the syntax of the language, but a "true"
> C<goto> disregarding matters of wether it is considered harmful or
> not, is first of all aesthetically unpleasant.
I couldn't care any less what coding fascists consider as unpleasant.
Klaus Schilling
------------------------------
Date: Mon, 2 Aug 2004 12:25:17 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Breaking out of nested subroutine?
Message-Id: <FVtPc.19633$Vm1.248446@news20.bellglobal.com>
<510046470588-0001@t-online.de> wrote in message
news:87brhu84jk.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me...
> Michele Dondi <bik.mido@tiscalinet.it> writes:
> > More precisely it is true that perl has some flavours of C<goto> in
> > disguise that blend nicely in the syntax of the language, but a "true"
> > C<goto> disregarding matters of wether it is considered harmful or
> > not, is first of all aesthetically unpleasant.
>
> I couldn't care any less what coding fascists consider as unpleasant.
>
So why do you keep posting?
Matt
------------------------------
Date: 02 Aug 2004 21:51:40 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Breaking out of nested subroutine?
Message-Id: <slrncgtdrc.i4t.abigail@alexandra.abigail.nl>
Sam Holden (sholden@flexal.cs.usyd.edu.au) wrote on MMMCMLXXXVIII
September MCMXCIII in <URL:news:slrncgqvuh.vgs.sholden@flexal.cs.usyd.edu.au>:
!! On 01 Aug 2004 22:23:44 GMT, Abigail <abigail@abigail.nl> wrote:
!! >
!! > I've no problem writing (in C):
!! >
!! > __close:
!! > if (close (fd) == -1) {
!! > if (errno == EINTR) {
!! > goto __close;
!! > }
!! > perror ("close");
!! > exit (1);
!! > }
!! >
!! >
!! > IMO, that's cleaner than introducing some extra variable and an extra loop.
!!
!! while (close (fd) == -1) {
!! if (errno != EINTR) {
!! perror ("close");
!! exit (1);
!! }
!! }
!!
!! Of course the if body could also be used with the goto replaced with
!! continue. The while loop, to me anyway, expressed what I'm trying to
!! do more clearly - keep trying to close fd if it fails temporarily.
!! But as always TIMTOWTDI.
I had to look at that code two times before it came clear to me. The
while() suggests you're going to retry untill it succeeds, but only on
closer inspection it turns out that you won't return to the guard if
the error is unequal to EINTR.
Personally, I prefer the if and the goto: if the close fails, I only
retry on EINTR.
Of course, it's just a matter of taste - syntactical nitpicking. The
semantics are exactly the same.
Abigail
--
perl -MLWP::UserAgent -MHTML::TreeBuilder -MHTML::FormatText -wle'print +(
HTML::FormatText -> new -> format (HTML::TreeBuilder -> new -> parse (
LWP::UserAgent -> new -> request (HTTP::Request -> new ("GET",
"http://work.ucsd.edu:5141/cgi-bin/http_webster?isindex=perl")) -> content))
=~ /(.*\))[-\s]+Addition/s) [0]'
------------------------------
Date: Tue, 03 Aug 2004 10:28:19 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Breaking out of nested subroutine?
Message-Id: <bvhug05t5tlk96raii1n9ijnef0iq7d93j@4ax.com>
On 02 Aug 2004 07:58:23 +0200, 510046470588-0001@t-online.de wrote:
>Michele Dondi <bik.mido@tiscalinet.it> writes:
>> More precisely it is true that perl has some flavours of C<goto> in
>> disguise that blend nicely in the syntax of the language, but a "true"
>> C<goto> disregarding matters of wether it is considered harmful or
>> not, is first of all aesthetically unpleasant.
>
>I couldn't care any less what coding fascists consider as unpleasant.
^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^
Idiot! Don't abuse words you don't have the slightest idea what they
mean. Were you aware of what you wrote, you should feel as deeply
humiliated by it as an arrogant beast like you can be.
There's hardly nothing I hate more than fascism, so don't call me
fascist. Do you know what fascism really is? Ignorance and arrogance,
mostly. Two "virtues" that you seem to possess in a highly
concentrated form...
For one thing one of fascists' mottos used to be (and still is, for
those motherfuckers who still are proud of calling themselves
fascists) "me ne frego", i.e. "I don't care", just as you "don't
care", disgusting dumbass: YOU ARE FASCIST!
Fascists do NOT care, since they are both ignorant and arrogant enough
to elect themselves to some inexistent title that allows them to
reject any other one's opinion. People, as opposed to fascists (that I
do not even consider "people" at all effects) DO care, my non-friend.
So I could have ignored your post and killfiled you, but I can't help
trying to ask you what in my words gave you the right to comment them
giving me *that* name. I was not trying to steal one's freedom to use
any construnct, just expressing a personal, subjective opinion, and
one indeed that is well subjective, but also widely shared on an
objective level and on reasonable basis.
Be ashamed of yourself: "people" are willing to learn. Fascists refuse
to. Go fuck yourself.
And no, do not complain for gratuitous insults, for (i) they're not
gratuitous, as nothing is as insulting as what you wrote in the first
place, (ii) you insulted yourself along with me.
Michele
--
Liberta' va cercando, ch'e' si' cara,
Come sa chi per lei vita rifiuta.
[Dante Alighieri, Purg. I, 71-72]
I am my own country - United States Confederate of Me!
[Pennywise, "My own country"]
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 6800
***************************************