Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
all your code examples are broken (multiply) and don't compile.

At the same time you claim the output is factual.

Please don't do this!!!

Point is that keys' prototype expects one %hash or @array not a scalar.

And the argument must start with % or @

DB<20> p prototype "CORE::keys" \[%@] DB<21> p keys @a DB<22> p keys %a DB<23> p keys $a Experimental keys on scalar is now forbidden at (eval 32)[c:/Strawberr +y/perl/lib/perl5db.pl:738] line 2. Type of arg 1 to keys must be hash or array (not scalar dereference) a +t (eval 32)[c:/Strawberry/perl/lib/perl5db.pl:\ 738] line 2, at EOF DB<24>

The point you should make is that there has to be exactly ONE argument!

That's why keys can't expect a LIST.

and this can't be changed with a new feature, because otherwise old code would break.

Consider

@all_keys = keys %h1, keys %h2;

which will parse like

@all_keys = keys(%h1), keys(%h2);

and collect the keys from %h1 and %h2

DB<26> %h1=(a=>1) DB<27> %h2=(b=>2) DB<28> x @all_keys = keys %h1, keys %h2 0 'a' 1 'b' DB<29>

Now, if keys LIST was allowed, than the first keys would try to consume the rest of the list.

@all_keys = keys( %h1, keys(%h2) );

That's why the idea of the OP can't be implemented, without breaking backwards compatibility!

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery


In reply to Re^10: Using 'keys' on a list (prototype & backwards compatibility) by LanX
in thread Using 'keys' on a list by lammey

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-18 02:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found