Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: find the element position of $scalar

by tadman (Prior)
on Feb 08, 2002 at 14:11 UTC ( [id://144104]=note: print w/replies, xml ) Need Help??


in reply to find the element position of $scalar

Here's a few quick bits of code.

Indexed iteration:
foreach my $i (0..$#array) { print "$i: $array[$i]\n"; }
Regular iteration with incremented tracker:
my $i = 0; foreach my $e (@array) { print "$i: $e\n"; $i++; }
Old-school C-style method:
for (my $i = 0; $i < @array; $i++) { print "$i: $e\n"; }
In this case, I'd say the first is "better" since it requires less code.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2024-04-26 08:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found