ctilmes has asked for the wisdom of the Perl Monks concerning the following question:
I can ask for a slurpy hash of named arguments with '*%args', or a slurpy array of non-named arguments with '*@args', but I want an ordered list of Pairs (specified with 'name => value'). Is there a good way to get that?
class testing { method newhash(*%args) { for %args.kv -> $k, $v { say "Hash Key $k => Value $v"; } } method newarray(*@args) { for @args -> $k, $v { say "Array Key $k => Value $v"; } } } my $x = testing.newhash(a => 1, b => 2); # Messes with specified ord +er my $y = testing.newarray(c => 3, d => 4); # Looks good, but doesn't w +ork my $z = testing.newarray('e', 5, 'f', 6); # Works, but ugly
Hash Key b => Value 2 Hash Key a => Value 1 Array Key e => Value 5 Array Key f => Value 6
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: [Perl6] Slurpy array of named arguments?
by TheDamian (Vicar) on Dec 05, 2016 at 19:24 UTC | |
Re: [Perl6] Slurpy array of named arguments?
by alexander_lunev (Pilgrim) on Dec 05, 2016 at 19:13 UTC |
Back to
Seekers of Perl Wisdom