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)!


In reply to Re: create an anonymous hash using "map" by parv
in thread create an anonymous hash using "map" by raygun

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.