I seek the wisdom of the monastery.
I can define a named hash using map:How do I define an anonymous hash using map?#!/usr/bin/perl $char = 0xE000; %characters = map { $_ => $char++ } ( 'first character', 'second character', 'third character' ); printf "First: %X; third: %X\n", $characters{'first character'}, $characters{'third character'};
I ask because defining character aliases under use charnames requires a similar syntax but using an anonymous hash. I can list the entries one by one:
But this clearly doesn't scale as well and is more error-prone if there are many entries. However, I can't find the right syntax for making that work using map.#!/usr/bin/perl use charnames ":alias" => { 'first character' => 0xE000, 'second character' => 0xE001, 'third character' => 0xE002 }; printf "First: %X; third: %X\n", ord("\N{first character}"), ord("\N{third character}");
In reply to create an anonymous hash using "map" by raygun
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |