A
ai2003lian
I'm new with perl. Sorry if this question is too naive. I have the
follwing piece of code, and I don't know why the variable $login apear
local:
#!/usr/local/bin/perl
package downlaod;
use Net::FTP;
use vars qw($ftp_server, $login, $password);
# Some settings
$idx = 0;
$next_arg = $ARGV[idx];
if(!$next_arg){
printUsage();
exit;
}
while($next_arg){
if($next_arg == "-h"){
$ftp_server=$ARGV[++$idx]; #the host name of the ftp
server
if (!$ftp_server){
printUsage();
exit;
}
print "$ftp_server \n";
}elsif($next_arg == "-u"){
$login=$ARGV[++$idx]; #user name
if (!$login){
printUsage();
exit;
}
print "$login \n";
}elsif($next_arg == "-p"){
$password=$ARGV[++$idx];
if(!$password ){
printUsage();
exit;
}
print "$password\n";
}
$next_arg = $ARGV[++$idx];
}
print "login= $login \n"; #problem here
sub printUsage(){
print "\aUsage: downlaod_zip_file -h <ftp server> -u <user
name> -p password \n";
}
when I try to print $login after the while loop, $login is empty! Why
is that? Please help!
Thanks in advance.
follwing piece of code, and I don't know why the variable $login apear
local:
#!/usr/local/bin/perl
package downlaod;
use Net::FTP;
use vars qw($ftp_server, $login, $password);
# Some settings
$idx = 0;
$next_arg = $ARGV[idx];
if(!$next_arg){
printUsage();
exit;
}
while($next_arg){
if($next_arg == "-h"){
$ftp_server=$ARGV[++$idx]; #the host name of the ftp
server
if (!$ftp_server){
printUsage();
exit;
}
print "$ftp_server \n";
}elsif($next_arg == "-u"){
$login=$ARGV[++$idx]; #user name
if (!$login){
printUsage();
exit;
}
print "$login \n";
}elsif($next_arg == "-p"){
$password=$ARGV[++$idx];
if(!$password ){
printUsage();
exit;
}
print "$password\n";
}
$next_arg = $ARGV[++$idx];
}
print "login= $login \n"; #problem here
sub printUsage(){
print "\aUsage: downlaod_zip_file -h <ftp server> -u <user
name> -p password \n";
}
when I try to print $login after the while loop, $login is empty! Why
is that? Please help!
Thanks in advance.