Regular expressions – Shielding strings in Perl using mask strings

I have a string like’xxox-x’, and I want to block every line in the file as follows:

> x Ignored (or just set to a known value)
> o stay the same
> – is a variable length field that can keep everything else unchanged

therefore masking’xxox- x’will produce’xxaxbeex’ for’deadbeef’

The same mask as’deadabbabeef”xxox-x’ will produce’xxaxabbabeex’

How can I use the s operation concisely Where is the symbol?

$mask =~ s/-/'o' x (length $str- length $mask)/e;
$str =~ s/(.)/substr($mask, pos $str, 1) eq'o'? $1:'x'/eg;

< /div>

I have a string like’xxox-x’, and I want to block every line in the file as follows:

> x is Ignore (or just set it to a known value)
> o stay the same
> – is a variable length field that can keep everything else unchanged

therefore masking’xxox-x ‘For’deadbeef’ will produce’xxaxbeex’

The same mask as’deadabbabeef”xxox-x’ will produce’xxaxabbabeex’

How can I use the s operator concisely Woolen cloth?

$mask =~ s/-/'o' x (length $str-length $mask)/e;
$ str =~ s/(.)/substr($mask, pos $str, 1) eq'o'? $1:'x'/eg;

Leave a Comment

Your email address will not be published.