Can anyone see a good way to load the RegExes from an eternal file?

There is probably a module for this somewhere, but if not, something along the lines of the following may serve. Your search patterns all seem to be plain octal sequences of various lengths and the replacement strings character string literals, so that simplifies things. I assume from your OP that you're confident about reading raw string data from a file and massaging it appropriately, so:

c:\@Work\Perl>perl -wMstrict -le "use Data::Dump qw(dd); ;; my @filelines = ( '\102\105\105 B', '\104\125\102\131\101 W', '\130 EKS', '\132 ZEE', ); ;; my %search_terms = map split, @filelines; ;; my %xlate = map { eval(qq{ qq{$_} }) => $search_terms{$_} } keys %search_terms ; dd \%xlate; ;; my ($search) = map qr{ $_ }xms, join ' | ', reverse sort keys %search_terms ; print $search; ;; my $s = 'the BEEroDUBYAn foX jumped the laZy dog'; print qq{'$s'}; ;; $s =~ s{ ($search) }{$xlate{ $1 }}xmsg; print qq{'$s'}; " { BEE => "B", DUBYA => "W", X => "EKS", Z => "ZEE" } (?^msx: \132 | \130 | \104\125\102\131\101 | \102\105\105 ) 'the BEEroDUBYAn foX jumped the laZy dog' 'the BroWn foEKS jumped the laZEEy dog'

Some other more or less random thoughts:

Update:
    $line =~ s/\302\240/\s/g;        # nbsp to sp
So, I guess this raises the question of just how you get a literal space from a space-delimited file to use as a replacement string, anyway? One way would be to use a non-space delimiter, but this may just shift the problem to another boundary. Another approach would be to specify all such characters in their octal equivalent,  \040 and so on. This sets us upon the the long and winding road of  s///ee and template processing (pursue the links from Re: Evaluating $1 construct in literal replacement expression). In any event, here's one way:

c:\@Work\Perl>perl -wMstrict -le "use Data::Dump qw(dd); ;; my @filelines = ( '\102\105\105 B', 'nbsp \040', '\130 EKS', '\132 ZEE', ); ;; my %search_terms = map split, @filelines; ;; my %xlate = map { eval(qq{ qq{$_} }) => $search_terms{$_} } keys %search_terms ; dd \%xlate; ;; my ($search) = map qr{ $_ }xms, join ' | ', reverse sort keys %search_terms ; print $search; ;; my $s = 'the BEErownbspfoX >nbsp< the laZy dog'; print qq{'$s'}; ;; $s =~ s{ ($search) }{ qq{ qq{$xlate{$1}} } }xmsgee; print qq{'$s'}; " { BEE => "B", nbsp => "\\040", X => "EKS", Z => "ZEE" } (?^msx: nbsp | \132 | \130 | \102\105\105 ) 'the BEErownbspfoX >nbsp< the laZy dog' 'the Brow foEKS > < the laZEEy dog'


Give a man a fish:  <%-{-{-{-<


In reply to Re: Read RegEx from file by AnomalousMonk
in thread Read RegEx from file by Melly

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.