Note that there are some explanatory texts on larger screens.

plurals
  1. POPerl script to modify file
    text
    copied!<p>I have Oracle files that I need to compare to CVS files, but the problem is that there are many files that I want to ignore the first line(s) as part of the diff. I want to run a script that opens each file, and replaces the file contents in such a way that the final output is replacing <code>'CREATE OR REPLACE PACKAGE "TRON"."SOME_PACKAGE" IS'</code> with <code>'CREATE OR REPLACE PACKAGE SOME_PACKAGE IS'</code>. The problem I am having is that the statement can span several lines, so I have to consider a situation like <code>'CREATE OR REPLACE "TRON"."SOME_PACKAGE" <br> IS'</code>.<br> </p> <p>My approach (since this is part of a Jenkins job), is to loop through all the files in the workspace, modifying any files that meet this criteria. I can then use my existing Perl script that is using <code>File::Compare</code> and <code>Text::Diff::Table</code>.</p> <p>I've been testing with <a href="https://stackoverflow.com/questions/7821795/perl-to-remove-lines-from-file">Zaid's solution</a> with little success, since it still is not dealing with scenarios where the command string spans multiple lines. (my changes):</p> <pre><code>use strict; use warnings; use Tie::File; use Data::Dumper; my @array; tie @array, 'Tie::File', 'c:\cb_k_check_recon_mma.sps' or die "Unable to tie file"; my %unwanted = map { $_ =&gt; 1 } map { $_-1..$_-4, $_, $_+2 .. $_+4 } grep { $array[$_] =~ /^CREATE.*[IS|AS]$/ } 0 .. $#array ; print Dumper \%unwanted; @array = map { $array[$_] } grep { ! $unwanted{$_} } 0 .. $#array; print Dumper \@array; untie @array; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload