Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array length 2

Status
Not open for further replies.

drkestrel

MIS
Sep 25, 2000
439
GB
Please refer to the code here...
Code:
my @failFs={};
#@files, $retruCounter to 3 and $notDone=1 initialised 
while ($retryCounter>0 and $notDone==1)
{
    print "No of Files to go- " .scalar(@files);
    $ftp =Net::FTP->new($host, debug=>1,Passive=>1) or die "couldn't connect";
    $ftp->login($userID,$passwd) or die "couldn't login";
    foreach $eachRemoteFile(@files)
    {
        $locFile = File::Spec->catfile($sourceDir,$eachRemoteFile);  
       	
       	$ftp->get($eachRemoteFile,$locFile) or (push @failFs,$eachRemoteFile);	
      	
    } #end foreach
    @files= @failFs;        #Files to be retried
    logDebug("No of files left-" . scalar(@files));
    if (scalar(@files)==1)
    {
        $notDone=0;
    }
    $ftp->quit();    ##Quit, retry to get the failed files, if needed
    
    $retryCounter--;
    
}#end while

The variable of interest is scalar(@files) at the end of the foreach. What I am doing here is FTP files contained in the original @files array.
If it failed, then put in @failFs array. At the end of the foreach{}. @files are set to @failFs. I would like a short cut to quite the while loop when no files are left, rather than iterating through the noOfRetry times, but it seems like scalar(@files) is always=1 after the first iteration. Why is that?
 
The problem is your definition of @failFs:
Code:
my @failFs={};
You are declaring @fileFs as an array and setting it's first element to a reference to an anonymous, empty hash. I tried that statement and then print @failFs and the first element contains a hash reference. Apparently, all your uploads are working successfully, so nothing else gets pushed into @failFs, but since it already contains one element (the hash ref) when you copy it to @files it also contains one element. What you meant to do to declare @failFs as an empty array is:
Code:
my @failFs=();
I.e. use parentheses instead of brackets (it's kind of hard to tell the difference in some fonts.
Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top