On 4/27/06, Rance Hall <[EMAIL PROTECTED]> wrote:
[snip]
> just to let everyone know, (I thought I had done this already but with
> the list reply stuff I messed that up)
>
> The problem is fixed, my split was correct, but my test to see if my
> split was correct was wrong
Glad you got it worked out!
> I was also printing the "count" of array elements and that apparently is
> also wrong, I was getting 1 when I should have got >1.
>
> The doc I read said that there is a special variable called #$arrayname
> that has the count of array elements.
>
> But this isn't correct, so how do you return the count of array elements?
>
I think this confuses pretty much everyone the first time they see it.
There are counts, and there are counts. #$array has the the index of
the last array element, wich is the count of elements starting from
zero. Since array indexes are zero-based, this is useful in things
like for loops:
for (0..#$arrayname) { print $array[$_] }
if you want the 1-based count of elements, you have a couple of
options. @arrayname gives the count in scalar context. You can get use
@arrayname in any scalar context, or you can ask for it explicity with
scalar(). It all depends on what you're doing.
print "my array has " . scalar(@arrayname) . " elements\n";
unless ( @arrayname == (#$arrayname + 1) ) {
print "something has gone horribly wrong!\n";
}
unless ( (@arrayname - 1) == #$arrayname ) {
print "seriously, mind-bendingly wrong!\n";
}
HTH,
-- jay
--------------------------------------------------
This email and attachment(s): [ ] blogable; [ x ] ask first; [ ]
private and confidential
daggerquill [at] gmail [dot] com
http://www.tuaw.com http://www.dpguru.com http://www.engatiki.org
values of β will give rise to dom!