Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Little things ;)

by IlyaM (Parson)
on Dec 13, 2001 at 17:27 UTC ( [id://131606]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://131606]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-03-29 07:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found