LexPl has asked for the wisdom of the Perl Monks concerning the following question:
It might puzzle you as a rather weird goal, but I would like to ask you nevertheless, because it would be extremely helpful to be able to do this :-)
Typically, a search and replace operation $_ =~ s/foo/bar/g; will be executed globally for the input file. Sometimes, you would like to decide for each individual match of the search string whether to replace it or not. This is what I mean by selective replace.
The script should have a loop that for each matching string
Would you think that this is feasible? And if yes, how could that be done? How would you interrupt processing, display stuff and take user input from the command line and finally continue processing?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Selective replace based on user input
by ikegami (Patriarch) on Nov 20, 2024 at 18:41 UTC | |
Re: Selective replace based on user input
by jdporter (Paladin) on Nov 20, 2024 at 16:28 UTC | |
Re: Selective replace based on user input -- oneliner
by Discipulus (Canon) on Nov 21, 2024 at 10:54 UTC | |
by ikegami (Patriarch) on Nov 22, 2024 at 21:46 UTC | |
by ikegami (Patriarch) on Nov 23, 2024 at 18:32 UTC |