John Degen wrote:

I'm using Perl 5.8.8 from ActiveState on Windows XP. I'm trying to
accomplish a search and replace in a number of files in the same
directory from the command line (cmd.exe). The problem is that the
command perl -i -e "s/old/new/" * fails silently, i.e. no changes
take place. My question is: does * indicate all files in the current
directory (this did work in the Windows version of sed I tried)? I
cannot find this in the docs or using Google. Or am I making another
mistake?

Hi John

Three problems here that I can see:

- Perl won't do an in-place edit successfully on a Windows system. You
 have to specify a name for the old file to be renamed to.

- It is the command shell on Unix systems that expands the wildcard
 into a list of filenames. On Windows your program sees just the single
 argument '*'.

- You have written no code to process the arguments passed. You program
 is simply

   s/old/new/

 which will just try to replace 'old' with 'new' in an uninitialised $_
 variable (try perl -w -i -e "s/old/new/" * to see the evidence).

I suggest you use something like

 perl -w -i.bak -p -e "s/old/new/"

but I haven't tested this as you already have a directory set up ready to
try it on :)

HTH,

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to