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....
Octavian
----- Original Message -----
From: "Rob Dixon" <[EMAIL PROTECTED]>
To: <beginners@perl.org>
Cc: "John Degen" <[EMAIL PROTECTED]>
Sent: Monday, June 18, 2007 5:48 PM
Subject: Re: [Perl 5.8.8 on WinXP] Command line usage
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/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/