View Full Version : Perl for Windows

07-09-2009, 07:43 AM
Hi Folks,

This is my first post.

I have already installed perl on unix, written some scripts (replacing scripts) and working fine. Iam now trying perl on windows. I had installed on windows too.

OS: Windows XP SP3
C:\>perl -v

This is perl, v5.10.0 built for MSWin32-x86-multi-thread
(with 9 registered patches, see perl -V for more detail)

The file "change.bat" contains

set CDIR=C:\
cd %CDIR%
perl -pi -e "s|changeover|changeafter|g" tochange.txt

I run the file (change.bat), but it does not change anything in the file "tochange.txt".
Am i missing anything? (For unix i used single quote and it works fine). I was told i should use double quotes on windows platform.

Do let me know, if anything else needs to be done.

if there is any other alternative on windows (any other freeware), that can be used for the same process?


07-09-2009, 02:05 PM
On Windows, you need to specify the ext for the backup file.

perl -pi.bak -e "s|changeover|changeafter|g" tochange.txt

07-10-2009, 12:10 PM
Hi FishMonger,
Great! Thanks its worked.
Thank you so much for pointing it.

BTW, i did run successfully by what is required to be changed.
But i also noticed that it creates a backup.
eg: I have some strings to be changed in myfile.bat and when i use the script to run, it did change the strings in myfile.bat, but eventually it also creates myfile.bat.bak

So is anything else missing? Because i do not want this bak file to be created. Irrespective of the extension in windows, the bak files creates? If that is the case, i have number of files which requires change of strings and each file it would have a .bak created! (Which i do not want). Then i need to include a del statement to delete those .bak files.
Correct me.

On Windows, you need to specify the ext for the backup file.

perl -pi.bak -e "s|changeover|changeafter|g" tochange.txt

07-11-2009, 01:18 AM
You have to delete the bak file if you don't want to keep it, but Windows does require you define a backup file extension before it will edit a file inplace. Sorry I forgot about that when I told you to use double-quotes on the other forum. You can use Tie::File (it comes with perl) to edit a file inplace and avoid the backup file issue. I leave it up to you to look into Tie::File.