#!/usr/bin/perl -w use diagnostics; use warnings; open $fh, "<", "$ARGV[0]" or die "Could not open $ARGV[0]: $!"; sub getsub{ my $sub = $_[0]; print "inside sub for $sub\n"; seek $fh, 0, 0; while (<$fh>) { if (/\.subckt $sub/../\.ends/) { print "starting from $_\n"; if (/^x/) { $line = $_; while (($nxt = readline($fh)) =~ /^\+/) { $line = $nxt; # print "line changed to $line\n"; } $line =~ s/\s+$//; # print "last line is $line\n"; my $sub = (split '\s', $line)[-1]; print "subcircuit found is $sub in $line\n"; my $pos = tell($fh); print "position in file set to $pos\n"; getsub ($sub); seek $fh, $pos, 0; $pos = tell ($fh); print "position in file restored to $pos\n"; print "line is now $_"; } } } } while (<$fh>) { if ($_ =~ /^xa1/) { $line = $_; print "line found to be $line\n"; while (($nxt = readline($fh)) =~ /^\+/) { $line = $nxt; #print "line changed to $line\n"; } $line =~ s/\s+$//; # print "last line is $line\n"; my $sub = (split '\s', $line)[-1]; print "subcircuit found is $sub in $line\n"; getsub($sub); } }