I am trying to create a script that will accept multi input from the user (really just me), then execute those command on a remote device.
My question is if the I enter "No" at the confirmation point "Are these statements correct y or n ?", what is the best way to go back and start over ? I have been trying different things with while and until flags but nothing is working.
#!/usr/bin/perl
use warnings;
use strict;
my @cmdlist;
my $cmd;
system("clear");
print "\nEnter one command per line then press enter.\n";
print "when you are complete entering data, press enter.\n";
while (<>) {
last if ($_ =~ /^\s*$/); # Exit if just spaces or an enter
print "You typed: $_";
push @cmdlist, $_;
}
#
system("clear");
print "The following is what will be sent to the remote device.\n" ;
foreach (@cmdlist) {
do
print "$_";
}
#
print "Are these statements correct y or n ?\n" ;
my $ans=<>;
if ($ans =~ m/n/i) {
print "No\n";
}
Thanks