Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: how can i get the index value of array during runtime

by siva kumar (Pilgrim)
on Mar 02, 2007 at 10:19 UTC ( [id://602853]=note: print w/replies, xml ) Need Help??


in reply to how can i get the index value of array during runtime

Will the below program solve your issue??
@array =qw (34 56 78 9); $index = 0; foreach (@array) { print "$index \t $_ \n"; $index++; }

Replies are listed 'Best First'.
Re^2: how can i get the index value of array during runtime
by GrandFather (Saint) on Mar 02, 2007 at 10:59 UTC

    If an "index" is required use $index as the identifier. If a count is required you need to pre-increment the value or set it to 1 initially.

    Yes, I know it is trivial sample code that doesn't matter, but good habits are worth acquiring. And distinguishing between a (1 based) count and a (0 based) index is a habit well worth acquiring!


    DWIM is Perl's answer to Gödel
      Gladly accepted your point ..
      :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-20 13:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found