in reply to create an anonymous hash using "map"
Here's one way:
#!/usr/bin/perl use strict; use warnings; my $char; BEGIN { $char = 1; } use charnames ":alias" => { map { $_ => $char++ } ( 'first character', 'second character', 'third character' )}; printf "First: %X; third: %X\n", ord("\N{first character}"), ord("\N{third character}");
Note: Using 0 as a value for $char didn't work.
Hope this helps!
update: fixed typo
|
---|