Richard Fernandez wrote:
> 
> I just had a situation where I needed to replace one string with another
> string in 200 files.
> This is what I came up with, but I know there has to be a better way. Below
> is my code.
> 
> "myfiles" contains a list of the files I need to scrub, one per line.
> 
> -------8<-----------------8<-----------------------
> #!/usr/local/bin/perl -w
> use strict;
> $|++;
  ^^^^
You aren't printing to STDOUT.


> my @files = `cat myfiles` or die;
> for (@files) {
> 
>         chomp;
>         push @ARGV, $_;
> }

You could also write that as:

chomp( @ARGV = `cat myfiles` );
@ARGV or die;


> $^I = ".bak";   # Got this from a previous message; thanks Peter!
> while (<>) {
> 
>         s#/u01/app/webMethodsFCS#/u02/app/webMethodsFCSclone#g;
>         print;
> 
> }
> ---------8<------------------8<-----------------------
> 
> Seems to me there should be a way to provide the filenames on the command line

There certainly is.

> w/o having to read the list into an array first, but I tried using
> xargs (this is unix) and a couple of other things but couldn't figure it out.

Assuming 'yourprogram' is your perl program.

yourprogram *

Stores all non-hidden files in @ARGV.

yourprogram xyz*

Stores all files that start with 'xyz' in @ARGV.

yourprogram `cat myfiles`

Stores the contents of myfiles in @ARGV.




John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to