RE: Change in "goto" behavior
Oh puleeze. Edsger was a very nice guy, but he was hardly one of the most brilliant minds in computer science --- and he certainly would have disapproved of Perl, whose author truly is a giant. Djiskstra hated "one-liners" -- since his main interest was mathematical proof of correctness, he promoted structured programming: a hierarchy of modules, each having a single entry and a single exit point, and in which control is passed downward through the structure without unconditional branches to higher levels of the structure. Three types of control flow are used: sequential, test, and iteration. While I'm being blasphemous: the inventor of C, Dennis Ritchie (also a Turing Award winner) was another real giant; and he and Thompson thought Stroustrup's C++ sucked. All the important OO concepts of abstraction, localism, etc were practiced by good C programmers well before C++, and neither C++ nor OO Perl can prevent stupid programmers from writing horrible code, goto's notwithstanding. Nor does an obsessive aversion to goto, continue or last indicate much other than OCD itself. > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On > Behalf Of John Deighan > I think that it's absurd to claim that work done by Edsger W. > Dijkstra, one of the most brilliant minds in Computer > Science, has been discredited by someone with lesser > credentials. The only case where I think that a 'goto' is > justified is when no other alternative is available in the > language you're using (usually a failing of the > language) that is as computationally efficient, and > computational efficiency is a major issue (it usually isn't). > I've used it, but only in a very few cases. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Change in "goto" behavior
At 09:55 AM 7/14/2005, Lloyd Sartor wrote: My opinion is that the goto statement can be useful in error handling situations, particularly when parsing data. This removes the rarely-executed error handling code from the expected, normal processing code. This makes the normal code more cohesive, understandable, and maintainable (IMO) because it remains sequential, uncluttered by unnecessary indentation, braces, etc. Of course, Perl provides synonyms for 'goto' in these scenarios (last, continue). If you try it, you'll find that using eval {} and die() is much better for error handling. Especially since you can die() in arbitrarily nested subroutines. Even C (at least C++) has a similar behavior via the "try" construct. I think that it's absurd to claim that work done by Edsger W. Dijkstra, one of the most brilliant minds in Computer Science, has been discredited by someone with lesser credentials. The only case where I think that a 'goto' is justified is when no other alternative is available in the language you're using (usually a failing of the language) that is as computationally efficient, and computational efficiency is a major issue (it usually isn't). I've used it, but only in a very few cases. Personally (and I hope I'm not starting a spam war here), I feel the same way about last and continue, which usually indicate a not-too-well thought out loop condition. We have 101,396 lines of production code with 2 goto's, 0 continue's and 7 last's. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Change in "goto" behavior
Bleh, Dijkstra is a quiche eater... Real programmers can write FORTRAN in any language http://ces.iisc.ernet.in/hpg/dhruba/Real.html -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Hugh Loebner Sent: Wednesday, July 13, 2005 9:26 PM To: Michael Erskine Cc: perl-win32-users@listserv.ActiveState.com Subject: Re: Change in "goto" behavior My previous message was attached to the wrong posting. I doubt very much whether there is any occasion where gotos are "most appropriate." Please provide an example. Check ot http://www.acm.org/classics/oct95/ "Go To Statement Considered Harmful" by Edsger W. Dijkstra On 7/13/05, Michael Erskine <[EMAIL PROTECTED]> wrote: > On Wednesday 13 July 2005 13:30, Hugh Loebner wrote: > > Why on earth are you using a goto statement? They are pernicious. > > On the contrary, a goto is often most appropriate in expressing clear > program flow. > > Regards, > Michael Erskine > > -- > Kinkler's First Law: > Responsibility always exceeds authority. > > Kinkler's Second Law: > All the easy problems have been solved. > ___ > Perl-Win32-Users mailing list > Perl-Win32-Users@listserv.ActiveState.com > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs > ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Change in "goto" behavior
"$Bill Luebkert" <[EMAIL PROTECTED]> wrote on 07/13/2005 10:36:04 PM: > > In structured programming practice, a goto would be totally inappropriate. > > But ... when you look at how a switch is implemented in actuality, it's > full of goto's. > > I guess the point is that you should leave the gotos to the underlying > generated compiler code and not use it yourself. But if your language > is lacking on suitable constructs, you may be forced to use a goto just > to save all the otherwise unnecessary code to go structured. > > My suggestion - avoid if possible - else use cautiously and infrequently. > My opinion is that the goto statement can be useful in error handling situations, particularly when parsing data. This removes the rarely-executed error handling code from the expected, normal processing code. This makes the normal code more cohesive, understandable, and maintainable (IMO) because it remains sequential, uncluttered by unnecessary indentation, braces, etc. Of course, Perl provides synonyms for 'goto' in these scenarios (last, continue). ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Change in "goto" behavior
On Thursday 14 July 2005 03:26, Hugh Loebner wrote: > My previous message was attached to the wrong posting. > > I doubt very much whether there is any occasion where gotos are "most > appropriate." Please provide an example. TMTOWTDI :) -- Do nothing unless you must, and when you must act -- hesitate. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Change in "goto" behavior
Dijkstra should have titled his letter "Stupid programmers considered harmful". A good programmer will write good code no matter how liberal the language, and a bad programmer will write bad code no matter how restrictive the language. Since someone asked, there's one situation where goto's are the best answer, even in fully structured languages: When you need to use a multitude of deeply and unevenly nested blocks to determine if some complex situation obtains, and there are several points in the nests at which the answer is determined. From each of those points you goto some code which does its thing and then exits, never trying to re-enter the nest. The alternative to goto in this one case is artificially contrived blocks that amount to structure for structure's sake. That's just an elaboratiuon of what $Bill said. Now can we end this religious discussion? Cliff > Behalf Of $Bill Luebkert > > My previous message was attached to the wrong posting. > > > > I doubt very much whether there is any occasion where gotos > are "most > > appropriate." Please provide an example. > > > > Check ot http://www.acm.org/classics/oct95/ "Go To Statement > > Considered Harmful" by Edsger W. Dijkstra > > In structured programming practice, a goto would be totally > inappropriate. > > But ... when you look at how a switch is implemented in > actuality, it's full of goto's. > > I guess the point is that you should leave the gotos to the > underlying generated compiler code and not use it yourself. > But if your language is lacking on suitable constructs, you > may be forced to use a goto just to save all the otherwise > unnecessary code to go structured. > > My suggestion - avoid if possible - else use cautiously and > infrequently. > > > On 7/13/05, Michael Erskine <[EMAIL PROTECTED]> wrote: > > > >>On Wednesday 13 July 2005 13:30, Hugh Loebner wrote: > >> > >>>Why on earth are you using a goto statement? They are pernicious. > >> > >>On the contrary, a goto is often most appropriate in > expressing clear > >>program flow. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Change in "goto" behavior
Hugh Loebner wrote: My previous message was attached to the wrong posting. I doubt very much whether there is any occasion where gotos are "most appropriate." Please provide an example. Check ot http://www.acm.org/classics/oct95/ "Go To Statement Considered Harmful" by Edsger W. Dijkstra of course, this has been discredited in the following discussion http://kerneltrap.org/node/553/2131, for languages that do not have the equivalent of last/next type constructs for exiting loops in the middle of the loop (like C). it's a bit harder to find a justification while coding in perl. :) ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Change in "goto" behavior
Hugh Loebner wrote: > My previous message was attached to the wrong posting. > > I doubt very much whether there is any occasion where gotos are "most > appropriate." Please provide an example. > > Check ot http://www.acm.org/classics/oct95/ "Go To Statement > Considered Harmful" by Edsger W. Dijkstra In structured programming practice, a goto would be totally inappropriate. But ... when you look at how a switch is implemented in actuality, it's full of goto's. I guess the point is that you should leave the gotos to the underlying generated compiler code and not use it yourself. But if your language is lacking on suitable constructs, you may be forced to use a goto just to save all the otherwise unnecessary code to go structured. My suggestion - avoid if possible - else use cautiously and infrequently. > On 7/13/05, Michael Erskine <[EMAIL PROTECTED]> wrote: > >>On Wednesday 13 July 2005 13:30, Hugh Loebner wrote: >> >>>Why on earth are you using a goto statement? They are pernicious. >> >>On the contrary, a goto is often most appropriate in expressing clear program >>flow. -- ,-/- __ _ _ $Bill LuebkertMailto:[EMAIL PROTECTED] (_/ / )// // DBE CollectiblesMailto:[EMAIL PROTECTED] / ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/ -/-' /___/_<_http://dbecoll.tripod.com/ (My Perl/Lakers stuff) ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Change in "goto" behavior
My previous message was attached to the wrong posting. I doubt very much whether there is any occasion where gotos are "most appropriate." Please provide an example. Check ot http://www.acm.org/classics/oct95/ "Go To Statement Considered Harmful" by Edsger W. Dijkstra On 7/13/05, Michael Erskine <[EMAIL PROTECTED]> wrote: > On Wednesday 13 July 2005 13:30, Hugh Loebner wrote: > > Why on earth are you using a goto statement? They are pernicious. > > On the contrary, a goto is often most appropriate in expressing clear program > flow. > > Regards, > Michael Erskine > > -- > Kinkler's First Law: > Responsibility always exceeds authority. > > Kinkler's Second Law: > All the easy problems have been solved. > ___ > Perl-Win32-Users mailing list > Perl-Win32-Users@listserv.ActiveState.com > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs > ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Change in "goto" behavior
I doubt this. Please provide an example. HLOn 7/13/05, Michael Erskine <[EMAIL PROTECTED]> wrote: On Wednesday 13 July 2005 13:30, Hugh Loebner wrote:> Why on earth are you using a goto statement? They are pernicious.On the contrary, a goto is often most appropriate in expressing clear programflow. Regards,Michael Erskine--Kinkler's First Law: Responsibility always exceeds authority.Kinkler's Second Law: All the easy problems have been solved.___ Perl-Win32-Users mailing listPerl-Win32-Users@listserv.ActiveState.comTo unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Change in "goto" behavior
> > > if ($choice !~ /^sub[12]$/) > { > &badchoice; > } > else > { > &{$hash{$choice}}; > } > Actually this if statement should've been if ($hash{$choice}) { &{$hash{$choice}}; } else { &badchoice; } Much more gooder than the regex. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Change in "goto" behavior
There is also discussion about implementing SWITCH equivilents in the perldoc for perlsyn under the heading 'Basic BLOCKs and Switch Statements'. Lou On 7/13/05, Thomas, Mark - BLS CTR <[EMAIL PROTECTED]> wrote: > John Deighan wrote: > > > We have a goto in our code. I hate it, but there just isn't a good > "switch" or "case" statement in Perl yet > > Yes there is, in Perl 5.8. If you're using an older Perl, you can still get > Switch.pm from CPAN. > > use Switch; > > switch ($val) { > case 1 { print "number 1" } > case "a"{ print "string a" } > case [1..10,42] { print "number in list" } > case (@array) { print "number in list" } > case /\w+/ { print "pattern" } > case qr/\w+/{ print "pattern" } > case (%hash){ print "entry in hash" } > case (\%hash) { print "entry in hash" } > case (\&sub){ print "arg to subroutine" } > else{ print "previous case not true" } > } > > ___ > Perl-Win32-Users mailing list > Perl-Win32-Users@listserv.ActiveState.com > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs > ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Change in "goto" behavior
Title: RE: Change in "goto" behavior This kind of flexibility in a switch statement reminds me why I love perl. Sam Gardner GTO Application Development Keefe, Bruyette & Woods, Inc. 212-887-6753 -Original Message- From: Thomas, Mark - BLS CTR [mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 13, 2005 10:46 AM To: 'John Deighan'; perl-win32-users@listserv.ActiveState.com Subject: RE: Change in "goto" behavior John Deighan wrote: > We have a goto in our code. I hate it, but there just isn't a good "switch" or "case" statement in Perl yet Yes there is, in Perl 5.8. If you're using an older Perl, you can still get Switch.pm from CPAN. use Switch; switch ($val) { case 1 { print "number 1" } case "a" { print "string a" } case [1..10,42] { print "number in list" } case (@array) { print "number in list" } case /\w+/ { print "pattern" } case qr/\w+/ { print "pattern" } case (%hash) { print "entry in hash" } case (\%hash) { print "entry in hash" } case (\&sub) { print "arg to subroutine" } else { print "previous case not true" } } ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Change in "goto" behavior
At 10:46 AM 7/13/2005, Thomas, Mark - BLS CTR wrote: John Deighan wrote: > We have a goto in our code. I hate it, but there just isn't a good "switch" or "case" statement in Perl yet Yes there is, in Perl 5.8. If you're using an older Perl, you can still get Switch.pm from CPAN. Great to know, but... What I see below looks semantically great - regular expressions and all that. However, that tells me that each case needs to be tried to find the matching case, which can be computationally very expensive, especially if there are hundreds of cases. What we need is a single (usually hash algorithm) lookup that determines very quickly the case that applies. That's what a "case" statement in Pascal (and, I think, a "switch" in C) does. That is also what a "goto $op" does in Perl, where $op must be the name of an existing label. One possibility is that Perl might check if every case value is a scalar, and generate the more efficient hash lookup method in that case. That would be great since it would basically optimize to the best method depending on the complexity of the case values, but I don't know if it does that. But, in our case, we definitely need the switch to be as efficient as possible. use Switch; switch ($val) { case 1 { print "number 1" } case "a"{ print "string a" } case [1..10,42] { print "number in list" } case (@array) { print "number in list" } case /\w+/ { print "pattern" } case qr/\w+/{ print "pattern" } case (%hash){ print "entry in hash" } case (\%hash) { print "entry in hash" } case (\&sub){ print "arg to subroutine" } else{ print "previous case not true" } } Scanned for Spam and Viruses. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Change in "goto" behavior
At 15:55 2005-07-13, John Deighan wrote: but that's another matter. (We initially used a "goto FINISH", but I hated that, too. You can use a "break" if you're in a loop.) We use a method that I really don't have time to describe now, but doesn't use a "goto". I hate goto's, but for the example above, it's efficient and much clearer than e.g. setting up a hash of op names and code to handle each op. I think you just demonstrated why the dispatch table really is the way to go :) For instance, did you remember to wrap the goto in an eval to catch missing labels? It's not that goto is inherently bad, but it has a so very, very, very specific niche in modern languages with other program flow constructs. The only useful example I can think of is in C where you can use it to simplify resource allocation/deallocation. But in Perl... no. Unless, of course, you're talking about goto LINE: http://search.cpan.org/~abergman/Acme-Goto-Line-0.01/Line.pm ;) /J -- --- -- -- -- - - -- - Johan LindströmSourcerer @ Boss Casinos johanl AT DarSerMan.com Latest bookmark: "TCP Connection Passing" http://tcpcp.sourceforge.net/ dmoz: /Computers/Programming/Languages/JavaScript/ 12 ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Change in "goto" behavior
>> At 08:30 AM 7/13/2005, Hugh Loebner wrote: >> >> Why on earth are you using a goto statement? They are pernicious. > > We have a goto in our code. I hate it, but there just isn't a good > "switch" or "case" statement in Perl yet (I think I've heard that it's > planned) It's not a case/switch, but you can do the same kind of thing with a hash: my %hash = ( sub1 => 'dothis', sub2 => 'dothat', ); print "Choose a sub: sub1, sub2: "; chomp(my $choice=); if ($choice !~ /^sub[12]$/) { &badchoice; } else { &{$hash{$choice}}; } sub dothis { print "You selected to dothis!\n"; } sub dothat { print "You selected to dothat!\n"; } sub badchoice { print "You don't follow directions very well.\n"; } ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Change in "goto" behavior
Title: Message John, Look up function dispatch tables on perlmonks.com. It's a pretty good alternative to switch case statements (better than if-else, anyway). But as to your question, I don't know if there was any functionality change made. Sam Sam Gardner GTO Application Development Keefe, Bruyette & Woods, Inc. 212-887-6753 -Original Message-From: John Deighan [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 13, 2005 9:55 AMTo: perl-win32-users@listserv.ActiveState.comSubject: Re: Change in "goto" behaviorAt 08:30 AM 7/13/2005, Hugh Loebner wrote: Why on earth are you using a goto statement? They are pernicious.We have a goto in our code. I hate it, but there just isn't a good "switch" or "case" statement in Perl yet (I think I've heard that it's planned), and the following just isn't efficient enough for us:if ($op = 'thisop') {}elsif ($op = 'thatop') {}...There are hundreds of possible values for $op. Anyway, I don't know how many people are aware of it, but the destination of a "goto" can be a variable, e.g.goto $op;thisop: do_this();thatop: do_that();Of course, you then have to prevent the fall through from the code for thisop: to the code for thatop:, but that's another matter. (We initially used a "goto FINISH", but I hated that, too. You can use a "break" if you're in a loop.) We use a method that I really don't have time to describe now, but doesn't use a "goto". I hate goto's, but for the example above, it's efficient and much clearer than e.g. setting up a hash of op names and code to handle each op. On 7/12/05, Dave Ressler <[EMAIL PROTECTED]> wrote: I have noticed a change in behavior in "goto" statements recently. Whereas a statement like "goto PLACE;" would work fine no matter where "PLACE:" was in my code, I've noticed that scripts that used to work are now failing at the "goto" statement. I can probably work out an example if needed, but the general question is: have any restrictions been put on "goto" recently? What are the real criteria needed to be satisfied for the destination to be successfully found? Thanks, Dave ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs Scanned for Spam and Viruses. Content-Type: text/plain; charset="us-ascii"MIME-Version: 1.0Content-Transfer-Encoding: 7bitContent-Disposition: inlineX-NAIMIME-Disclaimer: 1X-NAIMIME-Modified: 1___Perl-Win32-Users mailing listPerl-Win32-Users@listserv.ActiveState.comTo unsubscribe: http://listserv.ActiveState.com/mailman/mysubsScanned for Spam and Viruses. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Change in "goto" behavior
>(We initially used a "goto FINISH", but I hated that, too. You can use a "break" if you're in a loop.) you can also just surround the code in {} to make it a block and then use "last;" in perldoc -f last Note that a block by itself is semantically identical to a loop that executes once. Thus "last" can be used to effect an early exit out of such a block. What version of perl/platform are you using? Kind regards, Mark Anderson Team Leader - RSWI 1st Floor, The Broadstone 50 South Gyle Crescent Edinburgh, EH12 9UX Tel: 0131 523 7630 Mob: 07808 826 063 > -Original Message- > From: [EMAIL PROTECTED] > [SMTP:[EMAIL PROTECTED] > Sent: Wednesday, July 13, 2005 2:55 PM > To: perl-win32-users@listserv.ActiveState.com > Subject: Re: Change in "goto" behavior > > *** WARNING : This message originates from the Internet *** > > At 08:30 AM 7/13/2005, Hugh Loebner wrote: > > > Why on earth are you using a goto statement? They are pernicious. > > > We have a goto in our code. I hate it, but there just isn't a good > "switch" or "case" statement in Perl yet (I think I've heard that it's > planned), and the following just isn't efficient enough for us: > > if ($op = 'thisop') { > } > elsif ($op = 'thatop') { > } > ... > > There are hundreds of possible values for $op. Anyway, I don't know how > many people are aware of it, but the destination of a "goto" can be a > variable, e.g. > > goto $op; > > thisop: > do_this(); > thatop: > do_that(); > > Of course, you then have to prevent the fall through from the code for > thisop: to the code for thatop:, but that's another matter. (We initially > used a "goto FINISH", but I hated that, too. You can use a "break" if > you're in a loop.) We use a method that I really don't have time to > describe now, but doesn't use a "goto". I hate goto's, but for the example > above, it's efficient and much clearer than e.g. setting up a hash of op > names and code to handle each op. > > > > On 7/12/05, Dave Ressler <[EMAIL PROTECTED] > <mailto:[EMAIL PROTECTED]>> wrote: > > > I have noticed a change in behavior in "goto" statements > recently. Whereas a statement like "goto PLACE;" would work fine no matter > where "PLACE:" was in my code, I've noticed that scripts that used to work > are now failing at the "goto" statement. > > > > I can probably work out an example if needed, but the > general question is: have any restrictions been put on "goto" recently? > What are the real criteria needed to be satisfied for the destination to > be successfully found? > > > > Thanks, > > Dave > > > ___ > > Perl-Win32-Users mailing list > > Perl-Win32-Users@listserv.ActiveState.com > <mailto:Perl-Win32-Users@listserv.ActiveState.com> > > To unsubscribe: > <http://listserv.ActiveState.com/mailman/mysubs> > > > > > > _ > > Scanned for Spam and Viruses. > Content-Type: text/plain; charset="us-ascii" > MIME-Version: 1.0 > Content-Transfer-Encoding: 7bit > Content-Disposition: inline > X-NAIMIME-Disclaimer: 1 > X-NAIMIME-Modified: 1 > > ___ > Perl-Win32-Users mailing list > Perl-Win32-Users@listserv.ActiveState.com > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs > <http://listserv.activestate.com/mailman/mysubs> > > > Scanned for Spam and Viruses. > << File: ATT1514841.txt >> The Royal Bank of Scotland plc, Registered in Scotland No. 90312. Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB The Royal Bank of Scotland plc is authorised and regulated by the Financial Services Authority and represents The Royal Bank of Scotland Marketing Group. The Bank sells life policies, collective investment schemes and pension products and advises only on the Marketing Group's range of these products and on a With-Profit Bond produced by Norwich
RE: Change in "goto" behavior
John Deighan wrote, on Wed 7/13/2005 09:55 : We have a goto in our code. I hate it, but there just isn't a good "switch" or "case" statement in Perl yet (I think I've heard : that it's planned), and the following just isn't efficient enough for us:: if ($op = 'thisop') {: }: elsif ($op = 'thatop') {: }: There are hundreds of possible values for $op. Anyway, I don't know how many people are aware of it, but the : destination of a "goto" can be a variable, e.g.:: goto $op;:: thisop:: do_this();: thatop:: do_that(); Might I suggest a hash of sub refs? Then you can just do &{$my_subs{$op}}; or something like that. Good luck, Joe == Joseph P. Discenza, Sr. Programmer/Analyst mailto:[EMAIL PROTECTED] Carleton Inc. http://www.carletoninc.com 574.243.6040 ext. 300 fax: 574.243.6060 Providing Financial Solutions and Compliance for over 30 Years ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Change in "goto" behavior
On Wednesday 13 July 2005 13:30, Hugh Loebner wrote: > Why on earth are you using a goto statement? They are pernicious. On the contrary, a goto is often most appropriate in expressing clear program flow. Regards, Michael Erskine -- Kinkler's First Law: Responsibility always exceeds authority. Kinkler's Second Law: All the easy problems have been solved. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Change in "goto" behavior
John Deighan wrote: > We have a goto in our code. I hate it, but there just isn't a good "switch" or "case" statement in Perl yet Yes there is, in Perl 5.8. If you're using an older Perl, you can still get Switch.pm from CPAN. use Switch; switch ($val) { case 1 { print "number 1" } case "a"{ print "string a" } case [1..10,42] { print "number in list" } case (@array) { print "number in list" } case /\w+/ { print "pattern" } case qr/\w+/{ print "pattern" } case (%hash){ print "entry in hash" } case (\%hash) { print "entry in hash" } case (\&sub){ print "arg to subroutine" } else{ print "previous case not true" } } ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Change in "goto" behavior
At 08:30 AM 7/13/2005, Hugh Loebner wrote: Why on earth are you using a goto statement? They are pernicious. We have a goto in our code. I hate it, but there just isn't a good "switch" or "case" statement in Perl yet (I think I've heard that it's planned), and the following just isn't efficient enough for us: if ($op = 'thisop') { } elsif ($op = 'thatop') { } ... There are hundreds of possible values for $op. Anyway, I don't know how many people are aware of it, but the destination of a "goto" can be a variable, e.g. goto $op; thisop: do_this(); thatop: do_that(); Of course, you then have to prevent the fall through from the code for thisop: to the code for thatop:, but that's another matter. (We initially used a "goto FINISH", but I hated that, too. You can use a "break" if you're in a loop.) We use a method that I really don't have time to describe now, but doesn't use a "goto". I hate goto's, but for the example above, it's efficient and much clearer than e.g. setting up a hash of op names and code to handle each op. On 7/12/05, Dave Ressler <[EMAIL PROTECTED]> wrote: I have noticed a change in behavior in "goto" statements recently. Whereas a statement like "goto PLACE;" would work fine no matter where "PLACE:" was in my code, I've noticed that scripts that used to work are now failing at the "goto" statement. I can probably work out an example if needed, but the general question is: have any restrictions been put on "goto" recently? What are the real criteria needed to be satisfied for the destination to be successfully found? Thanks, Dave ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs Scanned for Spam and Viruses. Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-NAIMIME-Disclaimer: 1 X-NAIMIME-Modified: 1 ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs Scanned for Spam and Viruses. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Change in "goto" behavior
Why on earth are you using a goto statement? They are pernicious. HLOn 7/12/05, Dave Ressler <[EMAIL PROTECTED]> wrote: I have noticed a change in behavior in "goto" statements recently. Whereas a statement like "goto PLACE;" would work fine no matter where "PLACE:" was in my code, I've noticed that scripts that used to work are now failing at the "goto" statement. I can probably work out an example if needed, but the general question is: have any restrictions been put on "goto" recently? What are the real criteria needed to be satisfied for the destination to be successfully found? Thanks, Dave ___Perl-Win32-Users mailing listPerl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Change in "goto" behavior
- Original Message - From: "Dave Ressler" <[EMAIL PROTECTED]> To: "Perl List" Sent: Wednesday, July 13, 2005 11:06 AM Subject: Change in "goto" behavior > I have noticed a change in behavior in "goto" statements recently. Whereas a statement like "goto PLACE;" would work fine no matter where "PLACE:" was in my code, I've noticed that scripts that used to work are now failing at the "goto" statement. > > I can probably work out an example if needed, but the general question is: have any restrictions been put on "goto" recently? What are the real criteria needed to be satisfied for the destination to be successfully found? > Check 'perldoc -f goto'. If that doesn't answer the query, post a simple example that demonstrates the problem. The 'goto' documentation has changed a little from 5.6 to 5.8. I don't know whether that represents a change in functionality, or just a re-wording. Cheers, Rob ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Change in "goto" behavior
Dave Ressler wrote: > I have noticed a change in behavior in "goto" statements recently. > Whereas a statement like "goto PLACE;" would work fine no matter where > "PLACE:" was in my code, I've noticed that scripts that used to work are > now failing at the "goto" statement. Guess what Dave - I don't believe you. ;) > I can probably work out an example if needed, but the general question > is: have any restrictions been put on "goto" recently? What are the real > criteria needed to be satisfied for the destination to be successfully > found? Definitely provide an example - I don't think you can. -- ,-/- __ _ _ $Bill LuebkertMailto:[EMAIL PROTECTED] (_/ / )// // DBE CollectiblesMailto:[EMAIL PROTECTED] / ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/ -/-' /___/_<_http://dbecoll.tripod.com/ (My Perl/Lakers stuff) ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Change in "goto" behavior
I have noticed a change in behavior in "goto" statements recently. Whereas a statement like "goto PLACE;" would work fine no matter where "PLACE:" was in my code, I've noticed that scripts that used to work are now failing at the "goto" statement. I can probably work out an example if needed, but the general question is: have any restrictions been put on "goto" recently? What are the real criteria needed to be satisfied for the destination to be successfully found? Thanks, Dave ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs