in reply to Eek! goto?

Well, if you think that loop is scary, have you ever seen Duff's device? http://www.lysator.liu.se/c/duffs-device.html.

And of course, something like that can be ported to Perl:

#!/usr/bin/perl use strict; use warnings; my $n = shift; my $m = int (($n + 7) / 8); goto L . ($n & 7); L0: do { print "zero\n"; L1: print "one\n"; L2: print "two\n"; L3: print "three\n"; L4: print "four\n"; L5: print "five\n"; L6: print "six\n"; L7: print "seven\n"; } while -- $m > 0;

I'd love to be able to put something like that in a piece of production code.

Abigail

Replies are listed 'Best First'.
Re: Re: Eek! goto?
by BrowserUk (Patriarch) on Feb 12, 2003 at 11:18 UTC

    Wondribble!!


    Examine what is said, not who speaks.

    The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.

Re: Re: Eek! goto?
by hardburn (Abbot) on Feb 12, 2003 at 14:57 UTC

    The cool thing about Duff's Device is that it's surprising that a C compiler would actually accept it. In Perl, bizzare constructs are the norm, so I'm afraid the Perl version just isn't as cool (:

    ----
    Invent a rounder wheel.