OUTPUT:use v5.12; use warnings; # https://perlmonks.org/?node_id=11141581 my $in = "anXwxdXdzd"; my $pi = "1415926535"; my @in = split //, $in; my @pi = split //, $pi; my $re = join "", map {$in[$_] eq "X" ? $pi[$_] : '.' } 0..9; $re = "/bin/grep $re /path/to/some/file"; say $re;
/bin/grep ..1...6... /path/to/some/file
FWIW: Perl can apply mask operations with & , ^ and | , but this would also first require translating X to chr(255) and else to chr(0). see tr and s for that approach.
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
In reply to Re: string substitution
by LanX
in thread string substitution
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |