xa1 b t g e1
xa1 a s f a1
####
while (($nxt = readline($fh)) =~ /^\+/) {
##
##
.subckt a1 x y z
xa a b c1
xb c d e1
xc f g h1
.ends
.subckt c1 x y z
xa a b f
xb c d e
xc f g h
.ends
.subckt e1 x y z
xa a b c1
xb c d k1
xc f g h1
.ends
xa1 b t g e1
xa1 a s f a1
##
##
use strict;
use warnings;
open my $fh, '<', $ARGV[0]
or die "Cannot open file '$ARGV[0]' for reading: $!";
sub getsub
{
my ($sub) = @_;
print "inside sub for $sub\n";
seek $fh, 0, 0;
(/\.subckt $sub/ .. /\.ends/) && print while <$fh>;
}
my $line = <$fh>;
while ($line)
{
if ($line =~ /^xa1/)
{
print "line found to be $line\n";
my $next;
$line = $next while !eof && ($next = <$fh>) =~ /^\+/;
$line =~ s/\s+$//;
my $sub = (split /\s+/, $line)[-1];
print "subcircuit found is $sub in $line\n";
my $file_pos = tell $fh;
getsub($sub);
seek $fh, $file_pos, 0;
$line = $next;
}
else
{
$line = <$fh>;
}
}
close $fh
or die "Cannot close file '$ARGV[0]': $!";
##
##
13:20 >perl 1032a_SoPW.pl subs.txt
line found to be xa1 b t g e1
subcircuit found is e1 in xa1 b t g e1
inside sub for e1
.subckt e1 x y z
xa a b c1
xb c d k1
xc f g h1
.ends
line found to be xa1 a s f a1
subcircuit found is a1 in xa1 a s f a1
inside sub for a1
.subckt a1 x y z
xa a b c1
xb c d e1
xc f g h1
.ends
13:20 >
##
##
use strict;
##
##
#!/usr/bin/perl -w
...
use warnings;