in reply to Re: create an anonymous hash using "map"
in thread create an anonymous hash using "map"
produces the error:#!/usr/bin/perl 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}");
So it accepts the syntax of the alias setup, but doesn't actually create the aliases.Unknown charname 'first character' at ./mytest line 10, within string Execution of ./mytest aborted due to compilation errors.
If you're suggesting I use your assignment statement as written and then use your $characters variable to do the alias setup, I can't even find the right syntax for that. This gives syntax errors on the use charnames line, as I would expect (as did a couple variants I tried):
#!/usr/bin/perl $characters = { map { $_ => $char++ } 'first character', 'second character', 'third character' }; use charnames ":alias" => $characters;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: create an anonymous hash using "map" (compile time)
by LanX (Saint) on Aug 07, 2024 at 11:41 UTC |