* Chris Devers <[EMAIL PROTECTED]> [2002-11-20 16:19]:
> On Wed, 20 Nov 2002, darren chamberlain wrote:
> > I think the answer is to use a C-style for loop:
> >
> > for (my $i = 0; $i < $#array; $i++) {
> > # $i is your "iterator"
> > # $array[$i] is the "current" element
>
> What is the advantage of that over something like:
>
> my $iterator = 0;
> foreach my $elem (@array) {
> $iterator++;
> # do stuff on $elem, which seems like it would
> # be the same thing as $array[$iterator] but not
> # necessarily the same as $otherarray[$iterator]
> }
Well, the first (C-style) is going away in Perl 6, right?
> These look roughly equivalent to me.
>
> Is there any significant difference, beyond style preference?
My C-style for loop (above) is identical to:
my $iterator = 0;
while ($iterator < $#array) {
$iterator++;
do "stuff";
}
Which is, I think, how it is implemented internally (I'm sure Dan will
correct me if this is not correct).
(darren)
--
Whatever is done for love is beyond good and evil.
-- Friedrich Neitzsche
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm