in reply to Using 'keys' on a list
well, how would you do it in other "more elegant languages"?
> I'm far far from a monk so bear with me, but I can't see why keys doesn't provide list context.
keys HASH operates on the datatype hash not list, which means something starting with a % sigil here
> "Experimental keys on scalar is now forbidden"
that's another topic which wouldn't have helped you much, but you "probably" would have been able to write keys {f()}
Questions are:
sub f { {a=>1,b=>2} }
sub lkeys { keys %{{@_}} }
HTH! :)
my preferred way to gain elegance would be a private method, operating on a reference
my $keys = sub { my $self =shift; keys %$self }; sub f { return { a=>1, b =>2 } } print for f->$keys;
> Also, is there a way of creating a hash for consumption by keys in the above situation which doesn't involve creating a hash reference from a list and then immediately dereferencing?
could you please elaborate? I don't understand the question ...
see also Re^10: Using 'keys' on a list (prototype & backwards compatibility) for a full explanation why your feature request can't possibly be implemented.
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Using 'keys' on a list
by lammey (Novice) on Jun 29, 2021 at 14:46 UTC | |
by LanX (Saint) on Jun 29, 2021 at 15:03 UTC |