Erm, no, I wouldn't expect that. A hash isn't just an even-sized list. It uses a hashing algorithm (hence the name "hash") to divide the data up into a series of arbitrarily-ordered buckets. The resulting data structure is almost completely unlike a list. Why would functions designed to work on such a structure also work on lists?

The only way I can squint hard enough at it to make keys work on a list would be if keys operated by flattening the hash into a list and then iterating over every other list element. And I can't for the life of me come up with a good reason for making keys work that way.

If there really are that many use cases for iterating every other element of a list, they would be much better served by adding a new keyword for that functionality than by bloating keys with an unnecessary and anti-performant hash-to-list conversion, particularly since the new keyword could be generalized to iterate over every Nth element of the list instead of only giving "even elements" and "odd elements" options.


In reply to Re^2: Why does 'keys' need a named hash? by dsheroh
in thread Why does ‘keys’ need a named hash? by ankitpati

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.