in reply to better way to do N to 1 string mapping

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

  • Comment on Re: better way to do N to 1 string mapping