Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Perl for Windows

    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
    pause
    exit

    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.

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

    Thanks
    Last edited by kenkanya; 07-09-2009 at 08:27 AM.

  • #2
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,953
    Thanks
    2
    Thanked 172 Times in 167 Posts
    On Windows, you need to specify the ext for the backup file.

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

  • Users who have thanked FishMonger for this post:

    kenkanya (07-10-2009)

  • #3
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.


    Quote Originally Posted by FishMonger View Post
    On Windows, you need to specify the ext for the backup file.

    perl -pi.bak -e "s|changeover|changeafter|g" tochange.txt
    Last edited by kenkanya; 07-10-2009 at 12:45 PM.

  • #4
    Senior Coder
    Join Date
    Mar 2006
    Posts
    1,274
    Thanks
    2
    Thanked 39 Times in 38 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •