in reply to Regex substitute with both a sub and other data
$xml =~ s/(\<tag\>)(\d{11})(\<\/tag\>)/ $1 . md5_hex($2) . $3 /eg;
Update: Or, use a proper XML handling tool:
{ package XML::XSH2::Map; use Digest::MD5 qw( md5_hex ); } use XML::XSH2; xsh << '__XSH__'; open 1.xml; for my $n in //num[xsh:matches(., '^[0-9]{11}$')]/text() { my $s = string($n); insert text { md5_hex($s) } replace $n ; } ls / ; __XSH__
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex substitute with both a sub and other data
by FloydATC (Deacon) on Aug 23, 2013 at 10:41 UTC |