in reply to Re: Net::FTP troubles
in thread Net::FTP troubles
I agree about the foreach loop.
In addition, the actual error message (apparently) refers to the variable $IP as being undefined; this is because the assignment to $IP is using a different hash than the one that is being looped through. The loop starts with:
foreach $key(%Servers){
which loops through all of the key/value pairs of the hash %Servers in pseudo-random order (probably not what you wanted, as runrig has said). However, your assignment to $IP uses the variable $key to retrieve values from another hash called %Server, which is undoubtably empty, in fact making $IP undefined.
Also, as has been noted elsewhere, you most certainly do not need the double quotes around scalar values, for example, $Server{$key}: they force unnecessary interpolation, since $Server{$key} itself is already a string.
There is no particular reason to use a hash at all, preferring an array, which will preserve your ordering of IP addresses. I would go one step further and remove the unnecessary call to chomp (since the addresses do not end in newlines):
my @Servers = qw( 128.37.37.201 128.38.38.201 128.39.39.201 ); foreach my $IP ( @Servers ) { my $FTP = Net::FTP->new($IP); if ( $FTP->login($user,$pass) ) { $FTP->ascii(); $FTP->put($File); $FTP->quit; } else { print "Error logging in to $IP: ". $FTP->message ."\n"; } }
dmm
You can give a man a fish and feed him for a day ... Or, you can teach him to fish and feed him for a lifetime
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re(dmmiller2k): Net::FTP troubles
by Fastolfe (Vicar) on Nov 12, 2001 at 21:04 UTC |