question about data structures - what does $# mean?
- From: Ed <edwardjameshartnett@xxxxxxxxx>
- Date: Sat, 30 Aug 2008 05:21:14 -0700 (PDT)
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.
What's up with that?
As I read this, $d is a ref to an anonymous assoc. array, which
contains one pair of values, named sid, with an anonymous array
containing one element: "lll".
So to get the number of elements in the array I try:
$#{$d->{sid}}
But that does not work. It gives me 0.
Meanwhile, this does work:
scalar(@{$d->{sid}})
Which made me realize I don't really know what the # does when used in
$#{$d->{sid}}.
Any help would be appreciated!
Thanks,
Ed
.
- Follow-Ups:
- Re: question about data structures - what does $# mean?
- From: Dr.Ruud
- Re: question about data structures - what does $# mean?
- From: sanjeeb
- Re: question about data structures - what does $# mean?
- From: Jürgen Exner
- Re: question about data structures - what does $# mean?
- From: Joost Diepenmaat
- Re: question about data structures - what does $# mean?
- Prev by Date: Re: subprocesses lifecycle
- Next by Date: Re: question about data structures - what does $# mean?
- Previous by thread: trouble writing a setuid script
- Next by thread: Re: question about data structures - what does $# mean?
- Index(es):
Relevant Pages
|