P
pgodfrin
I have a need to pass a series of "edits" I'd like to apply in a
somewhat controlled manner.
My pseudo code would be something like:
1. accept as input the file name, old text, new text
2. check existence in file for old text, if not found error out
3. if found, then show before and after text for the whole line
4. Write out file.
I'm currently using @ARGV for #1 and I intend to slurp the whole file
into an array and then use map for #4.
I'm looking for ideas on a "perlish" way to do #2 and #3. The grep
function lets me show before and after like so:
print grep(/$oldtx/,@oldfile);
But I haven't checked for existence of the $oldtx as of yet. so a type
would make this print statement print nothing. I could always use
loops and other brute force methods - but it seems like there may be a
cooler, perlish way to this... Any ideas?
phil
somewhat controlled manner.
My pseudo code would be something like:
1. accept as input the file name, old text, new text
2. check existence in file for old text, if not found error out
3. if found, then show before and after text for the whole line
4. Write out file.
I'm currently using @ARGV for #1 and I intend to slurp the whole file
into an array and then use map for #4.
I'm looking for ideas on a "perlish" way to do #2 and #3. The grep
function lets me show before and after like so:
print grep(/$oldtx/,@oldfile);
But I haven't checked for existence of the $oldtx as of yet. so a type
would make this print statement print nothing. I could always use
loops and other brute force methods - but it seems like there may be a
cooler, perlish way to this... Any ideas?
phil