in reply to Can't get \n or other character/translation escapes to interpolate if originally read from a data file

Considering your responses further down in the thread, where you say you're actually looking to store sequences of search strings and replacements, I think perhaps it might be better to look at existing data serialization formats instead of inventing your own. For example, JSON is very common nowadays, or YAML is sometimes a bit more human-readable. In addition, since your search strings appear to be fairly similar, it's worth investigating whether a regex or two can match your search strings with more flexibility instead of listing all the search strings.

use warnings; use strict; use JSON::PP; use YAML::PP; my $data = [ { search=>"Reach Holly Smith for help by sending an email\nto holl +ysmith\@nosuchdomain.com.", replacement=>"For more information, conta +ct Holly Smith." }, { search=>"For more information, contact Holly Smith at\nhollysmit +h\@nosuchdomain.com.", replacement=>"For more information, contact Ho +lly Smith." }, { search=>"For more information, contact Holly Smith at (800) 555- +1212 or\nvia email to hollysmith\@nosuchdomain.com", replacement=>"Fo +r more information, contact Holly Smith." }, ]; my $json = JSON::PP->new->pretty; print $json->encode($data); my $yaml = YAML::PP->new; print $yaml->dump_string($data); __END__ [ { "search" : "Reach Holly Smith for help by sending an email\nto h +ollysmith@nosuchdomain.com.", "replacement" : "For more information, contact Holly Smith." }, { "replacement" : "For more information, contact Holly Smith.", "search" : "For more information, contact Holly Smith at\nhollys +mith@nosuchdomain.com." }, { "replacement" : "For more information, contact Holly Smith.", "search" : "For more information, contact Holly Smith at (800) 5 +55-1212 or\nvia email to hollysmith@nosuchdomain.com" } ] --- - replacement: For more information, contact Holly Smith. search: |- Reach Holly Smith for help by sending an email to hollysmith@nosuchdomain.com. - replacement: For more information, contact Holly Smith. search: |- For more information, contact Holly Smith at hollysmith@nosuchdomain.com. - replacement: For more information, contact Holly Smith. search: |- For more information, contact Holly Smith at (800) 555-1212 or via email to hollysmith@nosuchdomain.com
  • Comment on Re: Can't get \n or other character/translation escapes to interpolate if originally read from a data file
  • Download Code