Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
The problem is that, in the argument list of a sub or method, any key => 'value' pair with an unquoted key is always treated as a named argument. So any such argument it is always routed into the slurpy hash, and never into the slurpy array. The simplest solution is to quote the key of each pair, in which case they will be treated as positional arguments and will be routed into the slurpy array. Of course, each such positional pair will be a single Pair object (not a flattened list of key, value) so you will end up with an array of pairs, not an array of alternating keys and values. That means you'll need to unpack them differently in the for loop. Putting all that together, we get:
If you simply must have unquoted keys, then you'll need to pass an explicit list of them (in parens), because the "unquoted-means-named" magic only applies at the outermost level (known as the "comma level") of the argument list. So, with the rewritten newarray method above, the following would also work:
In reply to Re: [Perl6] Slurpy array of named arguments?
by TheDamian
|
|