in reply to Counting Elements output from Data::Dumper

Your result is returned as a reference to an array (which contains references to hashes - the whole is an AoH: Array of Hashes). You need an extra dereferencing step to get to the array itself. As LTjake says above, to get the length of the referenced array, do something like:
my $length=scalar @$config;
$config contains a reference to an array, which you can access by dereferencing it: prefix it with an @ symbol. @$config or @{$config} literally means: the array referenced by $config. If $config refered to a hash, you'd use %$config to get it.

Have a look at perlref for more information on references in Perl (which are somewhat like pointers in C, but then again, are not).

CU
Robartes-

Replies are listed 'Best First'.
Re: Re: Counting Elements output from Data::Dumper
by vbrtrmn (Pilgrim) on Nov 09, 2002 at 17:03 UTC
    my $length=scalar @$config; print $length;

    Returns an Invalid Server Error

    my $length=scalar %$config; print $length;

    Returns 1/8, I'm really not sure what that refers to, can you give me some more enlightenment?


    --
    paul
      Hi,

      the reason you get an error on scalar @$config is that I goofed :). I missed a level in the data structure referenced to by $config: it's actually a HoAoH (hash of arrays of hashes). So, to get the length of LOGENTRY, you need to access the value of the LOGENTRY key in the hash referenced by $config, and all that in scalar context. In other words: do what LTjake said :).

      print scalar %$config This is funny - what's happening here is that you're accessing a hash in scalar context ($config is a hash reference, so %$config is a hash. scalar puts it in scalar context.). This gives you the bucket efficiency of the hash, which is pretty useless in your case.

      Sorry for the goof-up.

      CU
      Robartes-