in reply to string substitution
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: string substitution
by LanX (Saint) on Feb 23, 2022 at 12:41 UTC | |
|
Re^2: string substitution
by Anonymous Monk on Feb 23, 2022 at 12:44 UTC | |
by LanX (Saint) on Feb 23, 2022 at 12:52 UTC |