On 9/21/05, Michele Dondi <[EMAIL PROTECTED]> wrote:
>
> Letting aside the fact that in the 99% of times they're plainly
> reinventing the wheel of glob() a.k.a. File::Glob, there are indeed
> situations in which one may have stuff like
>
> for (@foo) {
> next if $_ eq 'boo';
> # do something useful here
> }


I have mocked up an example of how you could do this in p5 with some ugly
looking code:

#!/usr/bin/perl
use strict;
use warnings;

do_something(5);

sub do_something {
my $target = shift;

my $block;

my $block2 = sub {
print "No need to check $_ against $target anymore\n";
};

my $block1 = sub {
no warnings;
if ( $_ == $target ) {
print "Skipping 5\n";
$block = $block2;
next LOOP;
}
else {
print "$_ is not $target\n";
}
};
$block = $block1;

LOOP:
for ( 1 .. 9 ) {
$block->();
}
}

Once the condition has been met, the code dynamically changes to no longer
check for the condition. Keep in mind, you are paying the price of
dereferencing as well as ENTER/LEAVE on subs to get this "performance"
benefit.

I will be interested to see what the experts say on this. I have often
desired this in long tight running loops and found that the ways to achieve
it (as shown above) are worse then leaving the op in.

Michele
>

Cheers,
Joshua Gatcomb
a.k.a. Limbic~Region

Reply via email to