Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: $# -variable?

by GrandFather (Saint)
on Jul 27, 2006 at 09:04 UTC ( [id://563990]=note: print w/replies, xml ) Need Help??


in reply to $# -variable?

$#array is the index of the last element of @array. Yes, you can use it as one end of the range of indexes as shown. However, that is hardly ever the Perl way. Generally if you want to run through the elements in an array you would:

for my $element (@array) { print "$element\n\n"; } # or using the default variable for (@array) { print "$_\n\n"; } # or using for as a statement modifier print "$element\n\n" for @array;

If you really need to index through the array then the Perlish way is to use a range (but see Flipin good, or a total flop?):

for (0..$#array) { print "$array[$_]\n\n" }

DWIM is Perl's answer to Gödel

Log In?
Username:
Password:

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

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

    No recent polls found