No such thing as a small change | |
PerlMonks |
Re^3: file modifications using file::findby eyepopslikeamosquito (Archbishop) |
on Jul 26, 2021 at 01:10 UTC ( [id://11135392]=note: print w/replies, xml ) | Need Help?? |
> I strive to do minimal processing within the File::find wanted routineSo do I! I find I grow fewer grey hairs that way. ;) To illustrate, here's a simple example of using File::Find to find all .txt files under the current working directory.
Example output of running this program:
Once I've built the list of files, I sometimes set about changing them in-place -- which is surprisingly tricky to do robustly, as described at Re-runnably editing a file in place (see also CPAN File::Replace by haukex, which nicely solves this problem). A practice exercise for the OP: extend the test program above to change all occurrences of Peking to Beijing in the .txt files (which I sometimes torture job applicants with :).
In Section
Seekers of Perl Wisdom
|
|