The program searches through directories looking for .report files and strips them of any quotations (') which allows the data to be inserted into oracle without errors.
#!/usr/bin/perl $DIR1="/users/model/data/reports"; $DIR2="/users/model/data/reports/temp"; &Filter($DIR1); &Filter($DIR2); exit(0); sub Filter { local($dir) = @_; opendir(DIR,$dir); while ($file = readdir(DIR)) { next if !($file =~ /\.temp/); unlink("$file");} closedir(DIR); opendir(DIR,$dir); while ($file = readdir(DIR)) { next if !($file =~ /\.report$/ ); open (INPUT,"<$file") || die "Error Opening File. $!\n"; open (OUTPUT,">>$dir/$file.temp") || die "Error Opening File for W +rite. $!\n"; foreach $read(<INPUT>){ if ($read=~ s/'//g) { print OUTPUT "$read"; } else {print OUTPUT "$read";} } close (INPUT); close (OUTPUT); } closedir(DIR); opendir(DIR,$dir); @model_reports = readdir(DIR); closedir(DIR); for (@model_reports) { next if !($_ =~ /\.temp$/ ); $oldname = $_; $_ =~ s/.temp//; rename("$dir/$oldname","$dir/$_"); #unix } }

Replies are listed 'Best First'.
Re: Strip Quotations from files
by FoxtrotUniform (Prior) on May 30, 2002 at 18:51 UTC

    Why not escape the quotes (by doubling them, IIRC) instead?

    Update: Good catch, grinder, but this script may be preparing files for a program somewhat less clever than DBI. If quotes are the only problem (which admittedly seems unlikely), why introduce dependencies?

    --
    The hell with paco, vote for Erudil!
    :wq

      Why not let DBI deal with the quoting issues (via the quote() method) instead?


      print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u'
        The script was written in the event that other special characters may need to be removed eg. &*^#@! All we have to do then is update the script.