laziness, impatience, and hubris | |
PerlMonks |
Re: Problem using Net::FTPby jarich (Curate) |
on Mar 04, 2004 at 18:59 UTC ( [id://333972]=note: print w/replies, xml ) | Need Help?? |
Okay, the problem is that you're ftping as many files as the info file provides you with. If this usually contains 2 files then that's great, but you probably want to allow it to later contain 3 or 4 or more, for flexibility's sake.
If you're happy with this idea, then you'll probably realise that specifying the directory that you want the file to be ftped into inside the info file, with the renaming information is a good idea. Before I get to that I just want to bring up one problem I immediately had with your script:
Firstly, I don't think you actually mean to have that > there. Secondly you're not checking that your open succeeded. What if you're not allowed to read the file? Permission denied? You should definately check this. So anyway, we can fix your code like this:
I really don't like your regular expression to pull the filenames out of the line. It's open to getting all sorts of things wrong. I'd suggest you instead change it to something like: This prevents people from entering the following lines and getting interesting results: In the first case it's pretty easy to spot what $1, $2 and $3 are set to and I hope you understand why that might be a bad thing. In the second case we get this: Why all those spaces when you have \s+? Because .* is greedy from the left, not from the right. I'd suggest you work out what characters you want to allow in your filenames and only accept those. I've given you a good start. [\w._-] only accepts letters, numbers, dots, underscores and dashs. If you need anything else then add that in... with caution. Oh, and make sure you add them before the dash, not after. This will probably help you in the future too. One final thing. Notice how using identation makes the script easier to read? You might want to make a special effort on that next time you post here. all the best, and I hope this helps jarich
In Section
Seekers of Perl Wisdom
|
|