Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^3: Syntax for casting map to a hash or an array

by haukex (Bishop)
on Apr 05, 2017 at 16:08 UTC ( #1187151=note: print w/replies, xml ) Need Help??


in reply to Re^2: Syntax for casting map to a hash or an array
in thread Syntax for casting map to a hash or an array

\@{ [map { $_ => 'fish' } qw(one two red blue)] }

Well, that works but it's a bit wasteful: first you're creating a arrayref with [], then you're dereferencing it with @{}, and then taking a reference to that again with \. It's easier to just use one set of []'s like 1nickt showed (although you may not have seen that yet since it was part of a large ninja edit).

Replies are listed 'Best First'.
Re^4: Syntax for casting map to a hash or an array
by cbeckley (Curate) on Apr 05, 2017 at 16:37 UTC

    I got there! In the end. Somewhat circuitously ...

    I knew this

    %{ {map { $_ => 'fish' } qw(one two red blue)} }
    returned a hash ...

    And I knew Dumper needed a reference ...

    And I suspected that if I could successfully pass Dumper a reference to an array I might finally understand what was going on with

    %{ { ... } }
    that bit.

    Thank you very much.

    Thanks,
    cbeckley

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2020-08-10 09:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which rocket would you take to Mars?










    Results (56 votes). Check out past polls.

    Notices?