in reply to foreach count variable

Okay, many are going to flame me, but this looks like an excellent occasion to use a C-type loop:

for (my $count = 0; $count < scalar(@bar); $count++) { printf "%d -> %s\n", ($count, $bar[$count]); }

Awaiting your scorn, -gjb-

Replies are listed 'Best First'.
Re: Re: foreach count variable
by andye (Curate) on Nov 18, 2002 at 21:46 UTC
    You needn't flinch, there's nothing wrong with that.

    An alternative is:

    my @foo = qw(one two three four); for (0..$#foo) { print "$_ : $foo[$_] \n"; }

    Andy.

Re: Re: foreach count variable
by dreamy (Sexton) on Nov 18, 2002 at 21:41 UTC
    yeah, thats the other way doing it.
    but still too much keys to press,
    and it looks quite 'untidy' :-)
Re^2: foreach count variable
by Aristotle (Chancellor) on Nov 20, 2002 at 15:49 UTC
    Your idea is fine, but the execution could be better.. :) There's no need for scalar nor printf there.
    for (my $count = 0; $count < @bar; $count++) { print "$count -> $bar[$count]\n"; }
    But then, I'd still prefer the for(0 .. $#bar) form proposed further down the thread.

    Makeshifts last the longest.