I am developing a script, which to delete the lines in a report, if matched expression are found in waiver file, which is a filtering file. Note that report format, the first few line are different format to the lines i want to check and delete if matched in waiver file. Report file:

**************************************** Report : noise_parameters Version : K-2015.12 Date : Mon Jul 24 02:42:46 2017 **************************************** analysis mode : report_at_source ignore arrival : true include beyond Rails : true enable propagation : true analysis type : violators **************************************** Report : noise -all_violators -nosplit -low -above Version: K-2015.12 Date : Mon Jul 24 02:42:46 2017 **************************************** analysis mode: report_at_source slack type: height noise_region: above_low pin name (net name) width height slack ----------------------------------------------------- es (esg) 135.42 0.37 -0.20 es (esh) 129.19 0.38 -0.17 es (esm) 184.15 0.49 -0.14 and so on...

waiver file:

es,135.42,0.37,"Waived,by","Waived,Date","Approved,by","Approved,date +" es,129.19,0.38,,"Waived,by","Waived,Date","Approved,by","Approved,dat +e"

output:

**************************************** Report : noise_parameters Version : K-2015.12 Date : Mon Jul 24 02:42:46 2017 **************************************** analysis mode : report_at_source ignore arrival : true include beyond Rails : true enable propagation : true analysis type : violators **************************************** Report : noise -all_violators -nosplit -low -above Version: K-2015.12 Date : Mon Jul 24 02:42:46 2017 **************************************** analysis mode: report_at_source slack type: height noise_region: above_low pin name (net name) width height slack ----------------------------------------------------- es (esm) 184.15 0.49 -0.14 es (esb) 208.55 0.48 -0.13 and so on

my code is like this

#! /tools/perl/5.8.8/linux/bin/perl use strict; use warnings; use Data::Dumper; # Source script my $report = $ARGV[1] ; my $waiver = $ARGV[3] ; my $result = $ARGV[5] ; # Set up a hash to receive the information my %identifier = (); # Read the violations file into the hash open my $filter, '<', $waiver or die; while (my $vline = <$filter>) { next unless $vline =~ /\S/; #skip blank lines my ($pins2, $w2, $h2) = split /,/, $vline; $identifier{$pins2}{'w2'} = $w2; $identifier{$pins2}{'h2'} = $h2; } print Dumper \%identifier; # Read input file line by line and compare 2 files open my $input, '<', $report or die; open my $output, ">", $result or die; while (my $wline = <$input>){ my ($pins1, $nets, $w1, $h1, $slack) = split /\s+/, $wline; # delete the contents if matched if (exists $identifier{$pins1}) { if ( ($w1 == $identifier{$pins1}{'w2'}) && ($h1 <= $identifier{$pi +ns1}{'h2'}) ) { my $start = 1; } else { my $start = 0; } } else { my $start = 0; } printf $output "$wline"; next if (my $start == 0); #if ($start == 0) { # printf $output "%-44s %-24s %-8s %-8s %-8s %-1 +0s\n", $pins1, $nets1, $w1, $h1, $slack; # } } close $filter; close $input; close $output;

In reply to Delete lines if matched expression by DespacitoPerl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.