Howdy:

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.

[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 $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);

# 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 script]

What I expected was to change the line that looks like 
this:

[snip wishful thinking output]
measure_id              integer,
code_set                character varying(100), **
label                   character varying(100), **
sex                     character(1),
[/snip wishful thinking output]


But I am getting this:

[snip error'ed output]

measure_id   integer,
code_set     character varying(100)(100)(100)(100)(100)(100)(100)(100),
label        character varying(100)(100)(100)(100)(100)(100)(100)(100),
sex          character(1),

[/snip error'ed output]


Can someone help me understand why I am getting the
extra (100)'s at the end and how to fix it?

Thanks!

-X

Reply via email to