in reply to Go to?

Perl does indeed have a goto function, but the last person that used it had his compter invade Poland whist his back was turned ;)

But seriously, looking to use a goto is generally a sign that your program logic is flawed, and perhaps some re-thinking is in order.

Update: I didn't realise (until I saw the response from monarch) that you had updated your original question with the example - obviously meant as a reply to this node. However, I still stand by what I said above. I've only been using Perl for a couple of years, but in that time I've never used a goto. I've no doubt that there may be the very odd situation where it's use is warranted, but I've yet to encounter one.

Cheers,
Darren :)

Replies are listed 'Best First'.
Re^2: Go to?
by gregor42 (Parson) on Apr 05, 2006 at 18:36 UTC

    Making blanket statements that goto is evil suffers from the dangers of Cargo Cultism.

    This is not to say that there isn't wisdom encapsulated there, but if it's learned behavior by ROTE rather than comprehension then the inherent wisdom is lost.

    goto, like a gun - isn't evil. It's what you do with it that counts.

    I'll not belabor the point already stated clearly by others.

    That being said - I haven't had a reason to use goto in perl personally. I'm intrigued by the prospect and I want to know more.

    That being said - I don't know if the OP has clearly stated what that reason is in his case. Rather they've been focusing on fending off the initial kneejerk reaction. That reaction however should have been expected.

    I don't see that it's necessarily wrong to question the motivation behind the choice however, since it's something that cuts against the grain of the party line concerning 'structured programming'. What I mean by that is simply that for those of us who started programming with a flavor of BASIC and then moved on to other languages, or who took an academic journey to become programmers - we have been taught that using goto is usually a sign that you're doing something 'wrong'. If nothing else it's a sign that you should be thinking about what you're doing very carefully - and the OP is clearly doing that.

    Ronnie can you please elaborate on the subject?



    Wait! This isn't a Parachute, this is a Backpack!
      Making blanket statements that goto is evil suffers from the dangers of Cargo Cultism.

      I couldn't agree more!
      By the way, who was it that said that goto is evil? (certainly not me)

      but if it's learned behavior by ROTE rather than comprehension then the inherent wisdom is lost.

      My sentiments exactly.

      I might also add that making assumptions (and drawing conclusions) about one's level of knowledge and experience based on minimal evidence often does the recepient no justice at all, and in some cases can cause hurt and resentment - which does nobody any good.

      But it's okay, because I'm not the type of person to take any of this personally :)

        By the way, who was it that said that goto is evil?

        Edsger W. Dijkstra in the classic paper "Go To Statement Considered Harmful" published in March 1968. This short paper is widely considered the seminal work which began the Structured Programming movement. (what do they teach in schools these days? :-) )

    A reply falls below the community's threshold of quality. You may see it by logging in.