Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^3: how many elements in array?

by bradcathey (Prior)
on Apr 18, 2005 at 13:02 UTC ( [id://448830]=note: print w/replies, xml ) Need Help??


in reply to Re^2: how many elements in array?
in thread how many elements in array?

Helpful in a loop as in:

for ( 0 .. $#one ) { ...do stuff to each element... }

—Brad
"The important work of moving the world forward does not wait to be done by perfect men." George Eliot

Replies are listed 'Best First'.
Re^4: how many elements in array?
by Limbic~Region (Chancellor) on Apr 18, 2005 at 13:11 UTC
    bradcathey,
    There are lots of ways in which $#array can be useful otherwise it wouldn't exist in the language. My point was more about correctness. For instance, if I am doing the following:
    my @ucase = grep { $_ eq uc() } @words; my $cnt = @ucase;
    I have the count of uppercase words, making all appropriate assumptions about @words. I would need to use $#ucase + 1* since it doesn't produce a count of elements otherwise. This was not clear from the post that I was replying to.

    Cheers - L~R

    * As RazorbladeBidet points out, modifying $[, is one highly discouraged way of accomplishing the same thing.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2024-04-25 08:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found