If you are concerned that your perl script will get unwieldy because of this long list, you have many options:

1) Put that list into a second script file, add "1;" as the last line and use require() to load it

2) Put that data into a config file and use a module like Config::Any, Config::JSON, Config::Auto (lots more available) to read that file

3) Use a database (if your data exceeds a few 1000 items)

4) Use a format of your own

Note that the resultant file handling, i.e. locating the config or data file and error handling, will add some lines of code so you should think about whether the smaller script file is worth the added complexity. But if you envision changing the data a lot, a config file might really be a good idea


In reply to Re: better way to do N to 1 string mapping by jethro
in thread better way to do N to 1 string mapping by tanyeun

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.