Tore Aursand <> wrote in message news:<>.. .
> On Thu, 04 Dec 2003 07:42:42 -0800, Tim Shoppa wrote:
> > Is there some magical variable like $. for array loops?
>
> No. You say that you've been programming Fortran, and you're saying - at
> the same time - that you're too lazy to write the following code?
>
> my $i = 0;
> foreach ( @array ) {
> $_ . ' at position ' . $i . "\n";
> $i++;
> }
>
> Crazy.
Creating a brand new variable with scope outside the loop body and no
use outside the body, which I then have to increment each time
around the loop (and remember not to "next" before the code that increments
it), when obviously the computer internally knows the index of the
element it's working on, isn't crazy?
And while everyone is telling me that I'm some thick-headed Fortran
programmer who doesn't know how to use Perl data structures, I
generally have to generate arrays in these forms because
other Perl modules from CPAN insist on non-structured arrays of
X-Y data. (Specifically, GD::Graph and Perl/Tk, but they take their
arrays in different orders... GD::Graph wants a list of x's and a list of
y's, while Perl/Tk generally wants x0-y0-x1-y1-x2-y2-etc.). I did
learn some less-than-elegant idioms for converting to/from these forms, though.
Tim.