question about data structures - what does $# mean?



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
.



Relevant Pages

  • Re: question about data structures - what does $# mean?
    ... $d is a ref to an anonymous assoc. ... contains one pair of values, named sid, with an anonymous array ...
    (comp.lang.perl.misc)
  • Process User
    ... Howdy! ... "System.Diagnostics.Process.GetProcesseses" will return an array of ... - Noah Coad - ... Microsoft MVP ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: snit newbie
    ... delegate method wag to mytail ... casual "Howdy!" ... I'm having trouble accessing "greeting" array. ...
    (comp.lang.tcl)
  • Re: need to go back three lines after a match
    ... >> Howdy, ... > You could read the file into an array and reversethe array (read ... > the file backwards). ... lines in an array, reverse it, and then print it out, I suppose. ...
    (comp.lang.perl.misc)
  • Re: Datagram byte[] values over 2^7-1
    ... >> mswope wrote: ... >>> Howdy! ... >>> I'm trying to construct an UDP datagram packet with an array of values. ...
    (comp.lang.java.help)