Hi! I tried a similar approach but facing problem in creating the hash structure..... in subroutine readDRC could u suggest .....
print " #!/usr/local/bin/perl ################################################ # Author : Sayandeep Nag # Date : 04 May 2004 # Description : Utility to Compare DRC Files ################################################ my $drcFile1 ; my $drcFile2 ; my $init1; my $init2; BEGIN { require Exporter ; use Carp ; # Initialize Global Variables ; $drc::error = " " ; $drc::warn = " " ; $drc::verbose = 0 ; $drc::DEBUG_ = 0 ; $drc::tmpFile = " " ; } $drc::flag = 0 ; use strict; # if( $#ARGV-1 <= 1 ) { # If File Name is Not Specifie +d as Input Argument # print "Enter The First DRC File : " ; # $drcFile1 = <STDIN> ; chop $drcFile1 ; # length $drcFile1 ; # print "Enter The Second DRC File : " ; # $drcFile2 = <STDIN> ; chop $drcFile2 ; # length $drcFile2 ; # } # else { # %{$ARGV[0]} = "" ; # %{$ARGV[1]} = "" ; $drcFile1 = $ARGV[0] ; # Else Take file Name from I +nput Argument $drcFile2 = $ARGV[1] ; # Else Take file Name from I +nput Argument # } $init1 = drcInit( $drcFile1 ) ; # Initialising the Inpu +t Files $init2 = drcInit( $drcFile2 ) ; if ( ($init1 == -1 ) or ($init2 == -1) ) { print "$drc::error\n" ; } # DRC Files Initialised # Processing of DRC files to Eliminate Comment +s Log ( " Processing DRC File $drcFile1\n " ) if ( $drc::verbose ) ; # If $drc::verbose is set my $retValue1 ; $retValue1 = processDRC ( $drcFile1 ) ; Log ( " Processing DRC File $drcFile2\n " ) if ( $drc::verbose ) ; # If $drc::verbose is set my $retValue2 ; $retValue2 = processDRC ( $drcFile2 ) ; return -1 if ( ($retValue1 == -1) or ( $retValue2 == -1) ) ; my $retValue2 ; Log ( " Reading DRC File $drcFile2\n " ) if ( $drc::verbose ) ; # If $drc::verbose is set $retValue2 = readDRC($drcFile1 , $drc::flag ) ; return -1 if ($retValue1 == -1) ; # Log ( " Reading DRC File $drcFile2\n " ) # if ( $drc::verbose ) ; # If $drc::verbose is set # $retValue2 = readDRC($drcFile2 , $drc::flag ) ; # return -1 if ( $retValue2 == -1) ; exit 0; ###################################################################### # Name : drcInit # Description : Subroutine to Initialise Input Files # Date : 4 May 2004 ###################################################################### sub drcInit { my ( $file ) = @_ ; $drc::error = "" ; $drc::warn = "" ; do { carp " No DRC File Given ." ; $drc::error = " No DRC File Given ." ; return -1 ; } unless ( defined $file ) ; # If No DRC File Specified do { carp " DRC File $file is Not a Plain Text File ."; $drc::error = " DRC File $file is Not a Plain Text File ."; return -1; } unless ( -f $file && -T $file ) ; # If File is not a vali +d Text File return 0 ; # Initialization Successful. } ###################################################################### # Name : processDRC # Description : Subroutine to Process Input Files and Eliminate # Comments # Date : 4 May 2004 ###################################################################### sub processDRC { my ( $file ) = @_ ; $drc::tmpFile = "${file}.tmp" if ($file) ; open ( TMPDRC, ">$drc::tmpFile" ); # Opening Temporary File + In Write Mode open (DRC , "<$file" ) ; # Opening DRC File in Read Mod +e Log ( " Reading DRC File $file..... ") if ($drc::verbose ); my $line ; my $prevLine ; my $lineNo = 0 ; while ( $line = <DRC> ) { $lineNo++ ; Log ( "." ) if ( $lineNo/1000==int($lineNo/1000) && $drc::ve +rbose) ; $line =~ s/\n//g ; next unless ( length $line ) ; # ignore blank lin +es. next if ( $line =~ m/^\s*\*/ ); # weed out commen +ts. next if ( $line =~ m/^\s*\|/ ); # weed out commen +ts. next if ( $line =~ m/^\s*\+/ ); # weed out commen +ts. print TMPDRC "$prevLine\n" if ( $prevLine ) ; $prevLine = $line ; } print TMPDRC "$prevLine\n" if ( $prevLine ) ; Log ( "... done.\n" ) if ( $drc::verbose ) ; close DRC ; close TMPDRC ; return 0; # Phase 1 successful. } ###################################################################### # Name : readDRC # Description : Subroutine to read Input Files and find differences # Date : 4 May 2004 ###################################################################### sub readDRC ( ) { my ( $file , $flag ) = @_ ; $drc::tmpFile1 = "${file}.tmp" if ($file) ; my $moduleName = "" ; my $netName ; my @gateInst ; my $gate ; my $netCap ; my $violation ; my @maxTrans ; my $worstTrans ; open ( TMPDRC, "<$drc::tmpFile1" ) ; my $line ; my $i; my $j = 0 ; @drc::file1 = <TMPDRC> ; for ( $i = 0 ; $i <= $#drc::file1 - 1 ; $i++ ){ if ( $drc::file1[$i] =~ m/^\s*\Module:/i ) { $moduleName = getModuleName ( $drc::file1[$i] ) ; } # End of IF Statement if ( $drc::file1[$i] =~ /Net:/ ) { $netName = getNetName ( $drc::file1[$i] ) ; } # End of IF Statement if ( $drc::file1[$i] =~ /Max Capacitance/ ) { @gateInst = getMaxCapacitance ( $drc::file1[$i] ) ; $gate = $gateInst[5].$gateInst[6] ; } # End of IF Statement if ( $drc::file1[$i] =~ /Net Capacitance/ ) { $netCap = getNetCapacitance ( $drc::file1[$i] ) ; } # End of IF Statement if ( $drc::file1[$i] =~ /VIOLATION/ ) { $violation = getViolation ( $drc::file1[$i] ) ; if ( $drc::flag ) { $drc::rpt1{$moduleName}{$netName}{$gate}{"Cap +acitance"} = $violation; } else { $drc::rpt2{$moduleName}{$netName}{$gate}{"Capaci +tance"} = $violation; } } # End of IF Statement if ( $drc::file1[$i] =~ /Max Transition/ ) { @maxTrans = getMaxTransition ( $drc::file1[$i] ) ; $gate = $maxTrans[5].$maxTrans[6] ; } # End of IF Statement if ( $drc::file1[$i] =~ /Pin Worst Transition/ ) { $worstTrans = getWorstTransition ( $drc::file1[$i] ) ; } # End of IF Statement if ( $drc::file1[$i] =~ /VIOLATION/ ) { $violation = getViolation ( $drc::file1[$i] ) ; if ( $drc::flag ) { $drc::rpt1{$moduleName}{$netName}{$gate}{"Tra +nsition"} = $violation } else { $drc::rpt2{$moduleName}{$netName}{$gate}{"Tran +sition"} = $violation } } # End of IF Statement # } # End of FOR Loop # if ($flag) {compareFiles(\@drc::rpt1 , \@drc::rpt2 , \$drc::tmpFile +1 ) } # Calling The Function to Compare Values # only if both Hashes are +assigned printValues(\@drc::rpt1) ; # my $caps = "Capacitance" ; # my $tran = "Transition"; # if ( $drc::rpt1{$moduleName}{$netName}{$gate}{$tran} != $drc::rp +t2{$moduleName}{$netName}{$gate}{$tran}) { # print " Module = $moduleName \n" ; # print " Net = $netName \n" ; # print " Gate = $gate \n" ; # print " Transition Violation Value = $drc::rpt1{$modu +leName}{$netName}{$gate}{$tran} \n" ; # print " Capacitance Violation Value = $drc::rpt1{$mod +uleName}{$netName}{$gate}{$caps} \n" ; # print " Transition Violation NEW Value = $drc::rpt2{$ +moduleName}{$netName}{$gate}{$tran} \n" ; # } # End of IF } # End of FOR Loop close TMPDRC ; $drc::flag = 1 ; # unlink ( $drc::tmpFile1 ) if ( -f $drc::tmpFile1 ) ; return 0 ; # mission successful :=) } ###################################################################### # Name : getModuleName # Description : Subroutine to read Input Files and find Module Names # Date : 4 May 2004 ###################################################################### sub getModuleName { my ($stmt) = @_ ; $drc::error = "" ; $drc::warn = "" ; my @parts ; $stmt =~ s/^\s*\Module:\s+//i; @parts = split /\s+/, $stmt ; if ( $drc::DEBUG_ ) { print "\t\tModule Name : $parts[0]\n" ; } if( $parts[0] ) { return $parts[0]; } else {return -1 ;} } ###################################################################### # Name : getNetName # Description : Subroutine to read Input Files and find Net Names in a + # Particular Module # Date : 7 May 2004 ###################################################################### sub getNetName { my ($stmt) = @_ ; $drc::error = "" ; $drc::warn = "" ; my @parts ; @parts = split /\s+/, $stmt ; if ( $drc::DEBUG_ ) { print "\t\t\tNet Name : $parts[2] \n" ; } if( $parts[2] ) { return $parts[2]; } else {return -1 ;} } ###################################################################### # Name : getMaxCapacitance # Description : Subroutine to read Input Files and find Net Names in a + # Particular Module # Date : 7 May 2004 ###################################################################### sub getMaxCapacitance { my ($stmt) = @_ ; $drc::error = "" ; $drc::warn = "" ; my @parts ; @parts = split /\s+/, $stmt ; if ( $drc::DEBUG_ ) { print "\t\t\t\t\t : $parts[5] $parts[6] \n" ; } if( $parts[2] ) { return $parts[2]; } else {return -1 ;} } ###################################################################### # Name : getNetCapacitance # Description : Subroutine to read Input Files and find Net Names in a + # Particular Module # Date : 7 May 2004 ###################################################################### sub getNetCapacitance { my ($stmt) = @_ ; $drc::error = "" ; $drc::warn = "" ; my @parts ; @parts = split /\s+/, $stmt ; if ( $drc::DEBUG_ ) { print "\t\t\t\t\t : $parts[4] \n" ; } if( $parts[2] ) { return $parts[4]; } else {return -1 ;} } ###################################################################### # Name : getViolation # Description : Subroutine to read Input Files and find Net Names in a + # Particular Module # Date : 7 May 2004 ###################################################################### sub getViolation { my ($stmt) = @_ ; $drc::error = "" ; $drc::warn = "" ; my @parts ; @parts = split /\s+/, $stmt ; if ( $drc::DEBUG_ ) { print "\t\t\t\t\t : $parts[3] \n" ; } if( $parts[2] ) { return $parts[3]; } else {return -1 ;} } ###################################################################### # Name : getMaxTransition # Description : Subroutine to read Input Files and find Net Names in a + # Particular Module # Date : 7 May 2004 ###################################################################### sub getMaxTransition { my ($stmt) = @_ ; $drc::error = "" ; $drc::warn = "" ; my @parts ; @parts = split /\s+/, $stmt ; if ( $drc::DEBUG_ ) { print "\t\t\t\t\t : $parts[5] $parts[6]\n" ; } if( $parts[2] ) { return @parts; } else {return -1 ;} } ###################################################################### # Name : getWorstTransition # Description : Subroutine to read Input Files and find Net Names in a + # Particular Module # Date : 7 May 2004 ###################################################################### sub getWorstTransition { my ($stmt) = @_ ; $drc::error = "" ; $drc::warn = "" ; my @parts ; @parts = split /\s+/, $stmt ; if ( $drc::DEBUG_ ) { print "\t\t\t\t\t : $parts[5] \n" ; } if( $parts[2] ) { return $parts[5]; } else {return -1 ;} } ###################################################################### # Name : compareFiles # Description : Subroutine to Compare Contents of two files stored in # two different hashes # Date : 7 May 2004 ###################################################################### sub compareFiles { my ($rpt1 , $rpt2 , $file) = @_ ; $drc::tmpFile2 = "${file}.tmp" if ($file) ; open ( TMPDRC, "<$drc::tmpFile2" ) ; @drc::file2 = <TMPDRC> ; print "$file \n" ; print " Main Hoon Naa \n" ; my $moduleName = "" ; my $netName ; my @gateInst ; my $gate ; my $netCap ; my $violation ; my @maxTrans ; my $worstTrans ; my $i ; my $caps = "Capacitance" ; my $tran = "Transition"; for ( $i = 0 ; $i <= $#drc::file2 - 1 ; $i++ ){ if ( $drc::file2[$i] =~ m/^\s*\Module:/i ) { $moduleName = getModuleName ( $drc::file2[$i] ) ; } # End of IF Statement if ( $drc::file2[$i] =~ /Net:/ ) { $netName = getNetName ( $drc::file2[$i] ) ; } # End of IF Statement if ( $drc::file2[$i] =~ /Max Capacitance/ ) { @gateInst = getMaxCapacitance ( $drc::file[$i] ) ; $gate = $gateInst[5].$gateInst[6] ; } # End of IF Statement if ( $drc::file2[$i] =~ /Net Capacitance/ ) { $netCap = getNetCapacitance ( $drc::file2[$i] ) ; } # End of IF Statement if ( $drc::file[$i] =~ /VIOLATION/ ) { $violation = getViolation ( $drc::file2[$i] ) ; # if ( $drc::flag ) { $rpt1{$moduleName}{$netName}{$gate}{"Capacit +ance"} = $violation; } # else { $rpt2{$moduleName}{$netName}{$gate}{"Capacitanc +e"} = $violation; } } # End of IF Statement if ( $drc::file2[$i] =~ /Max Transition/ ) { @maxTrans = getMaxTransition ( $drc::file2[$i] ) ; $gate = $maxTrans[5].$maxTrans[6] ; } # End of IF Statement if ( $drc::file2[$i] =~ /Pin Worst Transition/ ) { $worstTrans = getWorstTransition ( $drc::file2[$i] ) ; } # End of IF Statement if ( $drc::file2[$i] =~ /VIOLATION/ ) { $violation = getViolation ( $drc::file2[$i] ) ; # if ( $drc::rpt1{$moduleName}{$netName}{$gate}{$tran} != $drc::rp +t2{$moduleName}{$netName}{$gate}{$tran}) { # print " Module = $moduleName \n" ; # print " \t\t Net = $netName \n" ; # print " \t\t\t Gate = $gate \n" ; # print " \t\t\t\t Transition Violation OLD Value = $dr +c::rpt1{$moduleName}{$netName}{$gate}{$tran} " ; # print " \t\t\t\t Transition Violation NEW Value = $dr +c::rpt2{$moduleName}{$netName}{$gate}{$tran} " ; # } # End of IF } # End of IF Statement } # End of FOR Loop } # End of SUBROUTINE ###################################################################### # Name : searchModuleName # Description : Subroutine to read Input Files and find Module Names i +n # second file # Date : 6 May 2004 ###################################################################### sub printValues { my ($rpt1) = @_ ; my $module ; my $net ; my $gate ; my $vlte ; foreach $module ( keys %rpt1 ) { print "$module"; foreach $net ( keys %{ $rpt1{$module} } ) { print "{$net}" ; foreach ( keys %{ $rpt1{$module}{$net} } ) { print "{$gate}" ; foreach $vlte ( keys %{ $rpt1{$module}{$net}{$gate} } ) { print "{$vlte}" ; } } } } # if ( $drc::rpt1{$moduleName}{$netName}{$gate}{$tran} != $drc::rp +t2{$moduleName}{$netName}{$gate}{$tran}) { # print " Module = $moduleName \n" ; # print " \t\t Net = $netName \n" ; # print " \t\t\t Gate = $gate \n" ; # print " \t\t\t\t Transition Violation OLD Value = $dr +c::rpt1{$moduleName}{$netName}{$gate}{$tran} " ; # print " \t\t\t\t Transition Violation NEW Value = $dr +c::rpt2{$moduleName}{$netName}{$gate}{$tran} " ; # } # End of IF } ###################################################################### # Name : searchModuleName # Description : Subroutine to read Input Files and find Module Names i +n # second file # Date : 6 May 2004 ###################################################################### sub searchModuleName { # Subroutind to Search Module in Second +Temporary File my ($ModuleName , $file1 , $file2) = @_ ; open ( TMPDRC2, "<$file2" ) ; my $searchModule; my $line; my $i; @drc::file2 = <TMPDRC2> ; # Storing Contents of File in an Arr +ay for ( $i = 0 ; $i <= $#drc::file2 - 1 ; $i++ ){ if ( $drc::file2[$i] =~ m/^\s*\Module:/i ) { $searchModule = getModuleName ( $drc::file2[$i] ) ; } if ( $ModuleName eq $searchModule ) { print " $ModuleName Found in both files $i \n" ; } else { print " $ModuleName Not Found in second file $i\n" ; } } # End of While Loop close TMPDRC2; return 0; } # End of Subroutine searchModuleName ###################################################################### # Name : Log # Description : Subroutine Print Log Output # Date : 6 May 2004 ###################################################################### sub Log { my ( $msg ) = @_ ; print $msg ; } ";

In reply to Re: Re^3: Parsing A File by gautam_buddha
in thread Parsing A File by Anonymous Monk

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.