Really simple question.

Andy Armstrong andy at hexten.net
Thu Feb 8 16:12:52 GMT 2007


On 8 Feb 2007, at 15:35, Robert Bannocks wrote:
> i.e. in
>
> foreach (@arrayname)
> {
>  ...do some stuff..
> }
>
> other than setting a count before the loop and incrementing it each  
> time how can I find out with in ...do some stuff...
> how far through @arrayname I am?

The normal idiom is

    for my $i ( 0 .. $#arrayname ) {
        # do some stuff
    }

You can use C style for loops if you must

    for ( my $i = 0; $i < @arrayname; $i++ ) {
        # do some stuff
    }

It's generally neither necessary or desirable though.

-- 
Andy Armstrong, hexten.net



More information about the london.pm mailing list