Octavian Rasnita wrote:
Rob Dixon wrote:
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 :)
A program in command line that works might be too long under Windows,
but if it is necessary it could be made sending the list of files to the
program with a pipe, like:
dir /b | perl -e "print <STDIN>;"
This command prints the list of filenames on the console, and the dos
command dir accepts wildcards, then the perl program could do anything
with those files, like opening them, modifying....
(Please bottom-post your replies so that extended threads remain
comprehensible. Thank you.)
That is unnecessary. Just
perl -e "print qq($_\n) foreach <*>"
will do the same thing.
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/