----- Original Message ----- 
From: "Glenn Linderman"
.
.
>
> I think that the
>
> for( grep ($_ != 3, @a))
>
> is quite clear in bundling the element selection together, and
> separating it from the functions being performed.
>

I would much rather see (as suggested earlier on in this thread):

for(@a) {
     next if $_ == 3;

For me it is both clearer and more efficient ... but each to his own.

On the subject of replacing brackets with modifiers (which I think was also
raised earlier on), I was surprised to find that using a modifier is about
25% faster than brackets:


### try.pl ###
use warnings;
no warnings "once";
use Benchmark;

@x = (1 .. 1000000);
@y = (1 .. 1000000);

$z1 = 0;
$z2 = 0;

timethese(1, {
'modifier' => 'for(@x) {$z1++ if $_ != 3}',
'brackets' => 'for(@y) {if($_ != 3){$z2++}}',
});

print "\n", $z1, " ", $z2, "\n";
__END__

D:\pscrpt>perl try.pl
Benchmark: timing 1 iterations of brackets, modifier...
  brackets:  1 wallclock secs ( 1.03 usr +  0.00 sys =  1.03 CPU) @  0.97/s
(n=1)
            (warning: too few iterations for a reliable count)
  modifier:  1 wallclock secs ( 0.70 usr +  0.00 sys =  0.70 CPU) @  1.43/s
(n=1)
            (warning: too few iterations for a reliable count)

999999 999999

Maybe I've misinterpreted the results ??

Cheers,
Rob

_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to