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'
####
c:\@Work\Perl>perl -wMstrict -le
"my $s = '>nbsp< hi nbsp there';
print qq{'$s'};
;;
$s =~ s{ nbsp }{\s}xmsg;
print qq{'$s'};
"
Unrecognized escape \s passed through at -e line 1.
'>nbsp< hi nbsp there'
'>s< hi s there'
####
if($line =~ /[^[:ascii:]]/){
$line =~ s/([^[:ascii:]])/ ... lotsa subexpressions ... /ge;
print "Unhandled sequence: $line\n";
}
####
c:\@Work\Perl>perl -wMstrict -e
"my $s = 'aXbYcZd';
print qq{'$s' \n};
;;
print qq{unhandled sequence: '$s' \n}
if $s =~ s{ ([XYZ]) }{ sprintf '[%d/%1$#X/%1$#o]', ord $1 }xmsge;
"
'aXbYcZd'
unhandled sequence: 'a[88/0X58/0130]b[89/0X59/0131]c[90/0X5A/0132]d'
####
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'