Since your loops are nested, you move through the entirety of file2 before you go to the second line of file1. Perhaps you mean something more like (untested):
print HDLCGET "\#\!\/usr\/local\/bin\/expect\n"; print HDLCGET "set timeout -1\n"; open(MYINPUTFILE, "<", "hdlc2") or die "Open MYINPUTFILE failed: $!"; open(MYINPUTFILE1, "<", "hdlc3") or die "Open MYINPUTFILE1 failed: $!" +; while(<MYINPUTFILE>) { my($line) = $_; chomp($line); #my($line1) = <MYINPUTFILE1>; # This slurps the file - oops my $line1 = <MYINPUTFILE1>; chomp($line1); print HDLCGET "spawn \ ssh $line\n"; print HDLCGET "expect \"assword: \"\n"; print HDLCGET "send \"$tacacspw\\r\"\n"; print HDLCGET "expect \"#\"\n"; print HDLCGET "send \"terminal length 0\\r\"\n"; print HDLCGET "expect \"#\"\n"; print HDLCGET "send \"show xconnect all | inc $line1\\r\"\nexpect +\"#\"\n"; print HDLCGET "send \"exit\\r\"\n"; print HDLCGET "interact\n"; } close(MYINPUTFILE); close(MYINPUTFILE1);
Note also I swapped to the three-argument form of open and added a test to make sure the open succeeded - part of the same advice toolic gave you in Re: using multiple input files. Also, you might read How do I post a question effectively?, as debugging file-processing code w/o the files to be processed can be tricky.
Update: As discussed below, the above code was buggy. Corrected the error and kept the original line as a comment for posterity.
In reply to Re: Using multiple input files #2
by kennethk
in thread Using multiple input files #2
by ddrew78
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |