Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: quotation mark as key

by kcott (Archbishop)
on Aug 08, 2017 at 06:23 UTC ( [id://1196952]=note: print w/replies, xml ) Need Help??


in reply to quotation mark as key

G'day ic23oluk,

I see you've been given lots of advice on how to handle that specific character.

From your question, it appears that you may be attempting to hard-code each character and ASCII value. That's a lot of effort, and quite unnecessary, for your stated task: "ascii signs as keys, and the corresponding numbers as values". You can do that with a single statement:

my %hash = map { chr $_ => $_ } 32 .. 126;

That will give you a table of all, printable, 7-bit ASCII characters and their corresponding decimal values. You can test it like this:

$ perl -e 'use Data::Dump; my %h = map { chr $_ => $_ } 32 .. 126; dd +\%h' { " " => 32, "!" => 33, "\"" => 34, ... "|" => 124, "}" => 125, "~" => 126, }

Take a look at sprintf, if you want to format the values as hexadecimal, Unicode code points, HTML entity references, or something else. For example,

$ perl -e 'use Data::Dump; my %h = map { chr $_ => sprintf "U+%04X", $ +_ } 32 .. 126; dd \%h' { " " => "U+0020", "!" => "U+0021", "\"" => "U+0022", ... "|" => "U+007C", "}" => "U+007D", "~" => "U+007E", }

[Aside: I'm guessing English isn't your first language. The word you were looking for in your OP is "assign" ('n' and 'g' order reversed). The word "assing" means something else: I'll leave you to follow that link if want a chuckle. :-)]

— Ken

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-25 02:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found