Found the issue, which was my fault. By surrounding $line1 with parentheses in my($line1) = <MYINPUTFILE1>;, we moved to list-context. This means the entire file was being slurped, and the first element of the resulting list (i.e. line 1) was stored to the variable. On the subsequent iterations, the result was undef because the entire file had been read already. Working code:
use warnings; use strict; my $tacacspw = 'Kalewi13'; print "\#\!\/usr\/local\/bin\/expect\n"; print "set timeout -1\n"; open(MYINPUTFILE, "<", "hdlc2") or die "UNABLE TO OPEN FILE hdlc2: $!" +; open(MYINPUTFILE1, "<", "hdlc3") or die "UNABLE TO OPEN FILE hdlc3: $! +"; while(<MYINPUTFILE>) { my($line) = $_; chomp($line); my $line1 = <MYINPUTFILE1>; chomp($line1); print "spawn \ ssh $line\n"; print "expect \"assword: \"\n"; print "send \"$tacacspw\\r\"\n"; print "expect \"#\"\n"; print "send \"terminal length 0\\r\"\n"; print "expect \"#\"\n"; print "send \"show xconnect all | inc $line1\\r\"\nexpect \"#\"\n" +; print "send \"exit\\r\"\n"; print "interact\n"; } close(MYINPUTFILE); close(MYINPUTFILE1);
In reply to Re^3: Using multiple input files #2
by kennethk
in thread Using multiple input files #2
by ddrew78
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |