in reply to Login failure with net::Telnet
#Trying to get default values working here -- still working on it
Check out Getopt::Long - makes processing command line arguments a snap.
Instead of:chomp($ipbase = <STDIN>);
$ipbase = <stdin>; chomp ($ipbase);
There are several ways to do this - check out perlfaq8. (You'll probably want to use Term::ReadKey)#I would like to find a way to turn off echo or mask this portion print "Password:"; $password = <stdin>;
Is better written as:open(INFO,">$downreport");
Note that any OS error will be returned as the contents of $!. Also note the use of open with three arguments, instead of two. This is generally accepted as a better (and safer) practice.open INFO, '>', $downreport or die "Cannot open $downreport:$!\n";
See the docs on open for more information.open my $info, '>', $downreport or die "Cannot open $downreport:$!\n";
You could do something like:print "What is the base IP? (Example: 192.168.1)\n"; $ipbase = <stdin>; chomp ($ipbase); print "What is the bottom IP? (Default 1)\n"; $ipcurrent = <stdin>; chomp ($ipcurrent); print "What is the top IP? (Default 255)\n"; $ipend = <stdin>; chomp ($ipend); # etc....
And then:sub get_user_input { my $prompt = shift; print "$prompt\n"; return chomp(<STDIN>) }
There are further levels of abstraction that could be applied if you wanted to (a dispatch table, for example) - but I'm sure you get the idea ;)$ipbase = get_user_input("What is the base IP? (Example: 192.168.1)"); $ipcurrent = get_user_input("What is the bottom IP? (Default 1)"); $ipend = get_user_input("What is the top IP? (Default 255)");
Hope all the above helps,
Cheers,
Darren :)
|
|---|