CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
String Replacement in a text file

 



lokesh_nr
New User

Mar 24, 2015, 9:40 PM

Post #1 of 3 (23255 views)
String Replacement in a text file Can't Post

Hi Team,

This is one of the nice forums I have seen and need a quick help with perl code. I am taking a list of files in a directory and placing them in a file called files_2_delete.txt file. I want a code to run through the file, add 'del " ' in the beginning of the line and place " in the end of the line.

Sample file entries:

c:\SQL Backup\Trans1.trn
c:\SQL Backup\Trans2.trn
c:\SQL Backup\Trans3.trn
c:\SQL Backup\Trans4.trn

Output:

del "c:\SQL Backup\Trans1.trn"
del "c:\SQL Backup\Trans2.trn"
del "c:\SQL Backup\Trans3.trn"
del "c:\SQL Backup\Trans4.trn"

Thanks
Lokesh


FishMonger
Veteran / Moderator

Mar 25, 2015, 7:13 AM

Post #2 of 3 (23254 views)
Re: [lokesh_nr] String Replacement in a text file [In reply to] Can't Post

What have you tried?

What errors/warnings are you receiving?

How is the resulting text file going to be used? Is it going to be used in a batch file which executes each of those lines, or is it going to be used in a perl script to do the same thing?

IMO, adding the del to these lines is unnecessary since perl has the unlink function for deleting files.


Laurent_R
Veteran / Moderator

Mar 25, 2015, 10:47 AM

Post #3 of 3 (23222 views)
Re: [lokesh_nr] String Replacement in a text file [In reply to] Can't Post

Yeah, since you have the list of files in your Perl program, why don't you simply delete the file in this program? It seems so much simpler.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives