Thanks for the reply: Are you sure that the problem isn't in the 'for' loop? It seems odd that I have eight files in the directory and eight counts of the (100) at the end of the lines.
I am going to try something with the for loop and see if that gets me anywhere. Thanks again for that shorter version of the @list. Much cleaner than mine! -X >>-----Original Message----- >>From: John W. Krahn [mailto:[EMAIL PROTECTED] >>Sent: Tuesday, July 08, 2003 2:03 PM >>To: [EMAIL PROTECTED] >>Subject: Re: problems replacing a pattern in file >> >> >>Shaunn Johnson wrote: >>> >>> Howdy: >> >>Hello, >> >>> I have a script where I'd like to open a >>> bunch of files, search for a pattern and >>> replace it with another. >>> >>> What I am getting is not quite what I expected. >>> I get almost everything, but I'm getting a >>> bit more at the end. >> >>It looks like you are modifying the same file more than once (about >>eight times it seems.) You need to use a regular expression that >>matches "character varying" that is not followed by "(100)". >> >> >>> [snip script] >>> #!/usr/bin/perl -w >>> use strict; >>> use warnings; >>> use diagnostics; >>> use Cwd; >>> >>> # >>> # this is a script to look for and change some words >>> # for the sql scripts that i have lying around for production >>> # i'm at the point where i need to be a bit more lazy. >>> # >>> # yeah, i know ... >>> >>> # create a few variables >>> >>> my $sqldir=cwd; >>> my $pattern='character varying'; >> >>my $pattern = qr/character varying(?!\(100\))/; >> >> >>> my $new_ptrn='character varying(100)'; >>> >>> opendir (DIR, $sqldir) or die "can nae access the local >>directory: $!"; >>> # create and array and read in a list of files but NOT >>> # root and current dir >>> >>> my @list = grep {$_ ne 'temp' and $_ ne 'devel' and $_ ne >>'.' and $_ ne '..' >>> and >>> $_ ne 'chng_field.pl' and $_ ne 'backup_ddl' } readdir(DIR); >> >>If you have a long list of files to ignore I might do that >>differently: >> >>my %ignore = qw( >> . 1 >> .. 1 >> temp 1 >> devel 1 >> chng_field.pl 1 >> backup_ddl 1 >> ); >> >>my @list = grep !exists $ignore{$_}, readdir(DIR); >> >> >>> # create a loop to search for one instance of >>> # my password and change it to something else >>> # one day, i'll get smart and ask for a paramater, too >>> >>> for my $file(@list) { >>> open (FILE, $file) or die "can nae open this file: $!"; >>> >>> #local $^I=".bak"; # to keep a backup of the files >>> local $^I=""; # to keep a backup of the files >>> # set to "" if i don't want backups >>> local @ARGV = @list; # the files to work on >>> while (<>) { >>> s!$pattern!$new_ptrn!g ; >>> print; >>> } # end while loop >>> close (FILE); >>> } #end of for loop >>> >>> close (DIR); >>> >>> __END__ >>> >>> [snip] >> >> >>John >>-- >>use Perl; >>program >>fulfillment >> >>-- >>To unsubscribe, e-mail: [EMAIL PROTECTED] >>For additional commands, e-mail: [EMAIL PROTECTED] >>