Re: question about data structures - what does $# mean?
- From: Joost Diepenmaat <joost@xxxxxxxxx>
- Date: Sat, 30 Aug 2008 14:53:12 +0200
Ed <edwardjameshartnett@xxxxxxxxx> writes:
Howdy all!
Here's a little program:
#!/usr/bin/perl -w
my $d = {sid=>["lll"]};
print $#{$d->{sid}}."\n";
I expect this to print 1, but it prints 0.
0 is the correct response.
perldata says:
$days # the simple scalar value "days"
$days[28] # the 29th element of array @days
$days{’Feb’} # the ’Feb’ value from hash %days
$#days # the last index of array @days
Since perl arrays are indexed starting at 0 by default, an array
containing 1 element has a "last index" value of 0.
As you noted, the correct way to find out the length of an array is to
use scalar(@array).
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
.
- References:
- Prev by Date: question about data structures - what does $# mean?
- Next by Date: Re: question about data structures - what does $# mean?
- Previous by thread: question about data structures - what does $# mean?
- Next by thread: Re: question about data structures - what does $# mean?
- Index(es):
Relevant Pages
|