I'm am not a programmer by any means but I have used Perl to accomplish a few tasks in the past. At the moment I need a script to read file names from a file that I create from an 'ls' command. Then I need it to connect to a remote server and put those file(s) in the remote directory.

Why should we want to kill you for that? No point, really. You are shooting the bullet into your head yourself, you don't need any help for your suicide, you're doing it yourself very properly and very efficiently...

Otherwise, I have not used the Net::FTP module in ages and don't know if your FTP commands are correct, but I can spot a couple of things that seem wrong or suboptimal to me.

The most important point is that the logic of your loop seems to be wrong:

Basically, you are reading the first filename in your array and then only enter the loop that is supposed to stop once the array has been exhausted, which will of course never happen, since you are not reading the array within the loop (unless your array has only one filename).

A couple of other observations: - chomp your filenames before you use them when they are obtained from a system command, it is very unlikely to work otherwise; - put the "use Net::FTP; " statement at the beginning of the script, not within the loop - the first "{" block opening is useless (and so is the corresponding closing statement) - don't name your array @array, it is clear it is an array from the sigil (the @ sign at the beginning), give it a name that make sense to your program, such as, say, @list_of_the_names_of_the_files_that_I_want_to_transfer (I am overdoing it somewhat here, but I hope you get the point, @list_of_files would already be much better) - if you open the FTP connection within the loop, then close it also within the same loop, before opening the next one (but it would probably make more sense to open the FTP connection only once, outside the loop, and handle only the tranfer of each file within the loop, and close the connection at the end). - there are better ways to list files and remove them that using the "system" command, look at the Perl built-in commands to do that (commands such as "glob", "readdirr, "unlink", etc.).

But, of course, the most serious errors listed above, you probably would have seen immediately if you had taken just a few minutes to indent your code correctly... And you would probably have saved a lot of hours wasted stupidly by usefully spending these few minutes.

The first problem I noticed was that you didn't include the strict pragma, which should be in every Perl script you write. The strict pragma will require you to declare your vars prior to using them, which is normally done with the 'my' keyword.

The warnings pragma should also be used instead of the -w switch. The switch and pragma do almost the same thing. The key difference is the switch is applied globally and can not be disabled if need be, whereas the pragma is lexically scoped and can be enabled/disabled at the block level.

So, your scripts should always begin like this:

Code

#!/usr/bin/perl

use strict; use warnings.

Instead of making a system call to the find command where you redirect its output, it would be more efficient to use Perl's File::Find or File::Find::Rule module to retrieve and store the file list in an array directly without the intermediate step of the external file.