in reply to string substitution
#!/usr/bin/perl use warnings; use strict; my @pi = split //, '1415926535'; while (<DATA>) { 1 while s/ ([^ ]*?)\Kx/$pi[length $1]/; print; } __DATA__ /bin/grep .......... /path/to/some/file /bin/grep xxxxxxxxxx /path/to/some/file /bin/grep x....x...x /path/to/some/file
For each x, find the string between it and its preceding space. Its length is the position in the "mask".
Update: If the path can contain x, you need more caution, e.g. s/^[^ ]+ ([^ ]*?)\Kx/$pi[length $1]/g.
|
|---|