CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [mpride] Net::FTP - Returing 'Bad remote filename" error: Edit Log



FishMonger
Veteran / Moderator

Dec 29, 2012, 7:21 AM


Views: 1147
Re: [mpride] Net::FTP - Returing 'Bad remote filename" error

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.

File::Find - http://search.cpan.org/~dom/perl-5.12.5/lib/File/Find.pm
File::Find::Rule - http://search.cpan.org/~rclamp/File-Find-Rule-0.33/lib/File/Find/Rule.pm

Similarly, Instead of the system call to the rm command, you should be using Perl's unlink function.
perldoc -f unlink http://perldoc.perl.org/functions/unlink.html


Quote

Code
open("list"); 
@array = <list>;
close("list");


That is not going to do what you expect and will generate several warnings.

You should use the 3 arg form of open, a lexical var for the filehandle, check the return code to make sure it was successful and take proper action if it wasn't.


Code
open my $file_listing_fh, '<', $list or die "failed to open '$list' $!";



(This post was edited by FishMonger on Dec 29, 2012, 7:22 AM)


Edit Log:
Post edited by FishMonger (Veteran) on Dec 29, 2012, 7:22 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives