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

Re: create an anonymous hash using "map"

by parv (Parson)
on Aug 07, 2024 at 08:22 UTC ( [id://11160898]=note: print w/replies, xml ) Need Help??


in reply to create an anonymous hash using "map"

Convert use charnames into BEGIN { ...; require charnames; ... } to be able to use %hash as the value for :alias export tag ...

# cat custom-name.pl; perl custom-name.pl use strict; use warnings; use Data::Dump qw[dump]; BEGIN { my $char = ord( q[a] ); my %hash = map { $_ => $char++ } qw[ aey bee ]; print dump( %hash ), qq[\n]; use v5.16; require charnames or die $@; charnames->import( q[:alias] => { %hash, q[cea] => $char } ); } printf qq[aey: %s\ncea: %s\n], qq[\N{aey}], qq[\N{cea}] ; ("bee", 98, "aey", 97) aey: a cea: c

... thanks to the response at https://stackoverflow.com/a/63018246, found via search for "perl begin use require export" as the documentation for use & require was inadequate.

Later I checked again & found use -- what I was really looking for (and realized MetaCPAN makes for a bad search engine for perl non-module documentation)!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-09-13 19:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (21 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.