#!/usr/bin/perl use strict; use warnings; use diagnostics; use Data::Dumper; # Define Files and assign strings my $infile = "Name.template"; my $outfile = "Name.lib"; my $start = "LIB_HEADER_START"; my $end = "LIB_HEADER_END"; my $rx_start = "RX_START"; my $rx_end = "RX_END"; my $infile_CSV = "Namepinlist.csv"; my $outfile_CSV = "Namepinlist.txt"; my $DIN_CAP = "0.0005"; my $DIN_PWR_ARC = "0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000"; sub main { # Open the input file open (my $infile1, '<', "$infile") or die "Unable to open $infile: $!\n"; # Open the output file open (my $outfile1, '>', "$outfile") or die "Unable to open $outfile: $!\n"; # Read each line of infile1 one by one until reaching 'LIB_HEADER_START' while(<$infile1>) { # Exit loop when 'LIB_HEADER_START' is found at the beginning of the line last if ($_ =~ m{\A $start }xms); } # Print each line of outfile1 until finding 'LIB_HEADER_END' to outfile while(<$infile1>) { # Exit loop when 'LIB_HEADER_END' is found at the beginning of the line last if ($_ =~ m{\A $end }xms); print $outfile1 $_; } # Read each line of infile1 one by one until reaching 'LIB_HEADER_START' while(<$infile1>) { # Exit loop when 'LIB_HEADER_START' is found at the beginning of the line last if ($_ =~ m{\A $rx_start }xms); } # Print each line of outfile1 until finding 'LIB_HEADER_END' to outfile while(<$infile1>) { # Exit loop when 'LIB_HEADER_END' is found at the beginning of the line last if ($_ =~ m{\A $rx_end }xms); print $outfile1 $_; } } sub mainCSV { # Open the CSV input file open (my $infile_CSV1, '<', "$infile_CSV") or die "Unable to open $infile_CSV: $!\n"; my %hash = (); my $hash_ref = {}; while (my $line = <$infile_CSV1>) { chomp; $line =~ s/\s*\z//; my @array_CSV = split /,/, $line; my $key_CSV = shift @array_CSV; if ($hash{$key_CSV}) { warn "Duplicate key '$key_CSV'"; }; $hash{$key_CSV} = \@array_CSV; } # Explicit scalar context my $size = scalar keys %hash; # Prints Number of Pins (Hash size...) print "Number of Pins: $size\n"; # Open the output file and save hash in $outfile_RX_CSV open (my $outfile2, '>', "$outfile_CSV") or die "Unable to open $outfile_CSV: $!\n"; print $outfile2 Dumper(\%hash); close $outfile2; print "Stored $size list of pins in $outfile_CSV file.\n"; # Continue print with corresponding hash key and value for AsyncInNoTimingArc my $count = grep { $_ eq 'AsyncInNoTimingArc' } values %hash; open (my $outfile1, '>>', "$outfile") or die "Unable to open $outfile: $!\n"; for (; $count >= 0; $count--) { print <<" EOF"; pin(\"$hash{$key_CSV} => {$values}\") { direction : input ; capacitance : $DIN_CAP ; } internal_power(pwr_arc){ values(\"$DIN_PWR_ARC\"); related_input : \"$hash{$key_CSV} => {$values}\" ; } EOF } } main (); mainCSV ();