in reply to Little things ;)

scalar(keys %hash)
is shorter :)

--
Ilya Martynov (http://martynov.org/)

Replies are listed 'Best First'.
Re: Re: Little things ;)
by helgi (Hermit) on Dec 14, 2001 at 16:23 UTC
    and

    my $numkeys = (keys %hash);

    is clearer still and not much longer.

    I believe very strongly in clarity when programming,
    "even" in Perl.

    Regards,
    Helgi Briem

      Update: hmm... on further reading, I think the original point was that you don't need the scalar instead of the notion that adding parens would clarify what keys was doing.... so, nevermind.


      Why would the parens make it any clearer? I think you might be misunderstanding whats happening here. From keys:

      In a scalar context [keys], returns the number of keys [in the hash]
      Comparing this to length (since it behaves in a similiar way) which of these is clearer:
      $x = length $y; $x = (length $y);

      It looks like you think (keys %y) behaves like @{[keys %y]}... i.e. return the list of keys, package them up into an array, then return the member count of the array.

      -Blake