- It doesn't validate your parameters
- It requires you to put your password on the command line, visible to a PS command in Unix
And the output:sub dbinfo() { use Term::ReadKey; my $helpinstructions = "Valid parameters are\n-h {host}\n" . "-d {database}\n" . "-u {user}\n" . "-p [password]\n"; my %mydbinfo = ( db => "", host => "", user => "", passwd => "" ); die $helpinstructions unless ($#ARGV > 5); for (my $i=0; $i <= $#ARGV; $i++) { $ARGV[$i]= "-?" if ($ARGV[$i] ne '-h' and $ARGV[$i] ne '-d' and $ARGV[$i] ne '-u' and $ARGV[$i] ne '-p' ); die $helpinstructions if ( $ARGV[$i] eq "-?" ) ; $mydbinfo{db} = $ARGV[++$i] if ( $ARGV[$i] eq "-d" ) ; $mydbinfo{host} = $ARGV[++$i] if ( $ARGV[$i] eq "-h" ) ; $mydbinfo{user} = $ARGV[++$i] if ( $ARGV[$i] eq "-u" ) ; if ( $ARGV[$i] eq "-p" ) { if ( $i ne $#ARGV) { $mydbinfo{passwd} = $ARGV[++$i]; } else { print "\nPlease Enter passwd: "; ReadMode 'noecho'; chomp($mydbinfo{passwd} = ReadLine); ReadMode 'normal'; print "\n\n"; } } } return %mydbinfo; } return true;
D:\Documents and Settings\timj\perl>testcommandline.pl -h localhost -d cddb -u timj -p Please Enter passwd: Name Title Phatfish Guaranteed Phatfish 15 Bethany Dillon Waking Up Bethany Dillon Bethany Dillon Bethany Dillon Imagination Nick Drake Made To Love Magic Nick Drake Five Leaves Left Nick Drake Bryter Layter D:\Documents and Settings\timj\perl>
The great thing is that you can directly replace your previous version of the dbsettings routine with this one, and there is no need to alter your existing scripts!
No comments:
Post a Comment