Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Using 'keys' on a list

by glycine (Sexton)
on Jun 29, 2021 at 17:57 UTC ( [id://11134457]=note: print w/replies, xml ) Need Help??

in reply to Using 'keys' on a list

>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?

this is because hash hope first argument is a hash or array, so if offer a list the first argument is first element of list.
so keys just can't work on 'a' (in your example)...
if want keys work on return values of f(), the list still need stored into hash or array.

my %hash = f(); my @keys = keys %hash;
but you hope finish in one line but don't want %{{}}
I can't offer any to avoid hash reference, but if the pupose just look tidy
maybe let subroutine f() return reference?
so we can use:
my @keys = keys %{f()}; #or in postfix dereferencing my @keys = keys f()->%*;
hope this can help.

edit:I see you say you don't want :(

Replies are listed 'Best First'.
Re^2: Using 'keys' on a list
by Anonymous Monk on Jun 30, 2021 at 12:02 UTC
    so keys just can't work on 'a' (in your example)...

    no, list in scalar context returns the last value

        That's wrong.

        got an example of a "list in scalar context" or "comma operator in scalar context" or whatever that returns something other than the last value? wantarray is cheating

      A "list in scalar context" doesn't exist.
      - Ron
        that doesn't make what glycine wrote any less wrong

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11134457]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-13 19:25 GMT
Find Nodes?
    Voting Booth?

    No recent polls found