lammey has asked for the wisdom of the Perl Monks concerning the following question:
Suppose a function f() returns an even-sized list e.g.
sub f {a=>1,b=>2}I'd like to interpret the list as a hash and list the keys with something like
say for keys f;
but this will produce an error - "Experimental keys on scalar is now forbidden" (I'm running perl 5.33.9). I've found what does work is
say for keys %{{f}};
but I find this kind of inelegant. I'm far far from a monk so bear with me, but I can't see why 'keys' doesn't provide list context.
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?
Back to
Seekers of Perl Wisdom