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


In reply to Re: quotation mark as key by kcott
in thread quotation mark as key by ic23oluk

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.