"Steven M. Klass" wrote:
>
> Hi all,
>
> I have some code below that I wrote. Before you thow-up when you see it,
> understand this is why I am posting it. I need to clean this up, even I
> think it's bad. I would like to get something simpler and more elegant, but
> not a 3 line replacement that only Larry could understand. Thanks so much
>
> <cut here>
>
> #!/bin/perl -w
> # Ok here is a quick summary of what this thing is supposed to do.
> # First we use the tool ./fh to go create the file hierachy file. This will
> # return something that looks like the following:
> # possibly the top cell
> # topcell : 1
> # subcell0 : 2
> # subcell1 : 2
> # subsubcell0 :3
> # subcell0 : 2
> # subcell2 : 2
> # subcell0 : 3
> # subcell1 : 3
> # subsubcell0 : 4
> # Now all I want to do is parse this file for individually created cells.
> # 1. So, I need to remove the first line - it's always garbage.
> # 2. I also need to remove any cells that contain "$" as they too aregarbage.
> # 3. I also want to strip the ":" and anything that follows
> # 4. Lastly, I don't want duplicates so I need to check them to make sure
> # the names (subcells) don't already exist.
> #
> # Ideally, this will not rewrite this to the 2nd file, because I dont' need
> # it, in fact I don't really even need the first one. All I need to be able
> # to do is to clean up the output (format it) and print it to the screen.
>
> my $FILEHIERTOOL = "./fh";
> my $design = "FPD33684B1.gds" ;
> print "..Examining the file $design for problems \n";
> # Open up the list of cells..
> system ("$FILEHIERTOOL -g $design -S > cells.list 2> /dev/null");
> open (CELL, "cells.list") || die "Can't access cells.list\n";
> open (LIST, ">cells.clean.list");
>
> while (<CELL>) {
> my $line = $_;
> chop($line);
> for ($line) {
> # Remove the first line -->>CHEESY<<-- (Solves #1)
> s/possibly.*/\ /;
> # Remove all Cadence PCells (Solves #2)
> s/\b.*\$.*//;
> # Remove every level of hier (Solves #3)
> s/\ :.*\n//;
> print LIST "$list";
> }
> }
> # Now this is all for the last step. It seems like overkill
> close CELL;
> close LIST;
> open (LIST, "cells.clean.list");
> while (<LIST>){
> my $string = $_;
> my $i;
> my %h = map { $_ => $i++ } split(/[\b\s]+/,$string);
> print join(" ", sort { $h{$a} <=> $h{$b} } keys %h);
> print "\n";
> }
> close LIST;
>From your description this should do what you want:
#!/usr/bin/perl -w
use strict;
my $filehiertool = './fh';
my $design = 'FPD33684B1.gds';
my $dirty_file = 'cells.list';
my %cells; # hash to store unique cells
print "..Examining the file $design for problems \n";
# Open up the list of cells..
system( "$filehiertool -g $design -S > $dirty_file 2> /dev/null" );
open DIRTY, "< $dirty_file" or die "Can't access $dirty_file: $!";
# 1. So, I need to remove the first line - it's always garbage.
<DIRTY>;
while ( <DIRTY> ) {
chomp;
# 2. I also need to remove any cells that contain "$" as they too
are garbage.
next if /\$/;
# 3. I also want to strip the ":" and anything that follows
s/:[^:]*$//;
# remove leading and trailing whitespace
s/^\s+//;
s/\s+$//;
# store unique cell names
$cells{$_}++;
}
close DIRTY;
print join ' ', sort { $cells{$a} <=> $cells{$b} } keys %cells;
print "\n";
__END__
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]