in reply to OO Control loops

Oh. My. Goth^WGod.
Do you really think this makes things _easier_?


By the way... Ever heard of CODE references (anonymous subs)?

2;0 juerd@ouranos:~$ perl -e'undef christmas' Segmentation fault 2;139 juerd@ouranos:~$

Replies are listed 'Best First'.
Re: Re: OO Control loops
by dash2 (Hermit) on Jan 04, 2002 at 15:43 UTC

    Well, obviously it is slower and uglier than using normal control loops, and I wouldn't suggest using it always. But if you have to write repeated control structures, and don't want to write the same code many times, it may be useful.

    As for subrefs, this code is essentially a pretty interface to them, though you can also use strings to eval. I assume what you are thinking of is:

    my $subref = sub {print shift() . "\n";}; my $subref2 = sub {print "Length is " . length shift() . "\n";}; foo($subref); foo($subref2); sub foo { my $code = shift; foreach (@some_array) { &$code($_); } }

    which is the same but less flexible. But maybe you have something else in mind.

    dave hj~

      Repeated control structures can be a sign of bad programming. But still, I'd rather use the same structure over and over than an OO way to obscurely do the same thing less efficiently.

      And about the subrefs: Sorry, my bad. I only saw the 'print ...' example and somehow didn't notice the other one. The example of what you thought I was thinking about, was not what I meant, but I still like that better than the OO thingy :)

      2;0 juerd@ouranos:~$ perl -e'undef christmas' Segmentation fault 2;139 juerd@ouranos:~$