PyrexKidd has asked for the wisdom of the Perl Monks concerning the following question:
I need to write a script that opens a file and either:
1) deletes the last line and replaces it. or alternatively.
2) compares the last line and if it is not equal to what I need it to be then it replaces it. I think option 1 will be simpler, so I'm going with that. However, the line that I need to inset must have the file name in it. ie: File name ABCD Replaced Line: <xxxx.xxx.xxx.xxx, "xxx", xx_ABCD, xxx="">
so I open my file by:#Takes file name from command prompt #Then assigns the name to str fileName $fileName = INFILE; #open the file and copy to an array open(INFILE) || die("Cannot Open File"); @aFile = <INFILE>; close(INFILE); # How do I get the script to continue if line 6 is # already deleted? # Delete line 6 splice(@aFile,5) || die("Line 6 is already deleted");
This is where I am stuck. I need to append the end of the file with a long string (see example above) that includes the file name. How difficult would it be to implement a test of the last string and output if the change had been made or not? Any assistance would be greatly appreciated. Thanks in advance
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Find and Replace
by kiruthika.bkite (Scribe) on Mar 25, 2010 at 03:53 UTC | |
|
Re: Find and Replace
by zwon (Abbot) on Mar 24, 2010 at 21:17 UTC | |
|
Re: Find and Replace
by toolic (Bishop) on Mar 24, 2010 at 21:21 UTC | |
|
Re: Find and Replace
by Anonymous Monk on Mar 24, 2010 at 21:09 UTC | |
|
Re: Find and Replace
by PyrexKidd (Monk) on Mar 25, 2010 at 16:03 UTC | |
by GrandFather (Saint) on Mar 25, 2010 at 23:14 UTC |