Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Array length

Array length

Array length

Please refer to the code here...

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)
    $ftp->quit();    ##Quit, retry to get the failed files, if needed
}#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?

RE: Array length

The problem is your definition of @failFs:

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:

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close