Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Of foreach loops and counting

by eak (Monk)
on Aug 09, 2000 at 19:42 UTC ( #27070=note: print w/replies, xml ) Need Help??


in reply to Of foreach loops and counting

The easiest way I know of is to do something like.
foreach (0..$#array){ # do stuff, $_ holds iteration num. }


--eric

Replies are listed 'Best First'.
RE: Re: Of for each loops and counting
by turnstep (Parson) on Aug 09, 2000 at 20:27 UTC

    Or if you really want to use one of Perl's special variables, try this:

    for ($[..$#array) { ## Foo }
    since "0" is not necessarily the first element of the array. Of course, nobody should ever, ever change the $[ variable except as part of an obfuscated perl program. :)

RE: Re: Of foreach loops and counting
by Cirollo (Friar) on Aug 09, 2000 at 19:44 UTC
    Ok, and then I would just get my array values with $array[$_] instead of having the value be in $_. Sounds good to me. Thanks.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://27070]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2022-01-21 21:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (59 votes). Check out past polls.

    Notices?