Re: [Perl 5.8.8 on WinXP] Command line usage



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
.



Relevant Pages

  • Re: Thinking outside the box on file systems
    ... (it would be pretty inefficient to allow infinite command lines). ... Windows makes the stupid choice that every single program has to invent ... and support wildcard expansion on its own. ... A BUG is a BUG is a BUG. ...
    (Linux-Kernel)
  • RE: re-setting boot partition
    ... Description of the Windows 2000 Recovery Console ... For a Microsoft Windows XP version of this article, ... MB of hard disk space on your system partition to hold the Cmdcons folder ... Windows NTBoot Console Command Interpreter. ...
    (microsoft.public.win2000.setup_upgrade)
  • RE: Win2000 Upgrade to SP3 Express Setup error.
    ... Start your computer with the Windows Setup floppy disks, ... MB of hard disk space on your system partition to hold the Cmdcons folder ... Windows NTBoot Console Command Interpreter. ... you cannot copy a file from the local hard disk to a floppy disk. ...
    (microsoft.public.win2000.setup_upgrade)
  • RE: Locating corrupt driver
    ... This article describes the functionality and limitations of the Windows ... Create and format partitions on drives. ... MB of hard disk space on your system partition to hold the Cmdcons folder ... Windows NTBoot Console Command Interpreter. ...
    (microsoft.public.win2000.applications)
  • >>>> NET SEND <<<<
    ... Windows Xp Net Send ... Net Send Command For Mac ... Net Send Syntax Dos ... Dos Net Send Commands ...
    (sci.lang.japan)