The perl quotemetaoperator usually works on the search side s///, but in generating code that needs to be compiled with eval, how should I protect REPLACEMENT, which should be used literally, but can contain bits like $1?
quotemeta
s///
eval
$1
With form code
my $replace = quotemeta $literal_replacement; my $code = eval <<EOCode; sub { s/.../$replace/ } EOCode
when will this lead to syntax errors or unexpected results?
, perl $, /e . , quotemeta , .
#!/usr/bin/perl $test="test"; $literal_replacement='Hello $1, or \1'; my $replace = quotemeta $literal_replacement; $test =~ s/test/$replace/; print $test,"\n";
:
Hello\ \$1\,\ or\ \\1
, , :
( /e, eval, /e). Perl 5 , , . , :
/e
my $foo = 5; my $bar = '$foo'; my $baz = "$foo $bar"; print "$baz\n"; #this is 5 $foo not 5 5
$test =~ s<test>'$replace';
Source: https://habr.com/ru/post/1764366/More articles:Loop through NSArray objectAtIndex - objectAnonymous functions pre PHP 5.3.0 - phpСамый обычный метод хранения данных XYZ в MATLAB - matlabDrupal: "previous and next" links in each node? - drupalProblem validation problem model ASP MVC DateTime - datetimeКакое простейшее изменение CSS, которое может привести к драматическим (неразрушающим) эстетическим изменениям в веб-дизайне? - cssМожете ли вы объяснить, какие символы и символы отладки в мире С++? - c++C ++ visual studio inline - c ++Python check type - pythonTouch screen responds to hidden links - jqueryAll Articles