Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: New to Perl: Finding files on FTP

by Klaas (Initiate)
on Mar 14, 2012 at 18:03 UTC ( #959645=note: print w/ replies, xml ) Need Help??


in reply to Re: New to Perl: Finding files on FTP
in thread New to Perl: Finding files on FTP

Thanks! You are right, I don't need to change the directory. Let me experiment with your code a bit, need to understand the map function and get a better grasp of the

while ($dir_listing[0] =~ /^\.+$/) { shift @{$dir_listing}; }
I guess I would do this with a for loop, so I can just shift $dir_listing at position i. And I need to search all the subdirs as well, but I think I'll find a way. Thanks again!


Comment on Re^2: New to Perl: Finding files on FTP
Download Code
Re^3: New to Perl: Finding files on FTP
by runrig (Abbot) on Mar 14, 2012 at 20:29 UTC
    If you can't change to the directory, you probably can't list the directory or get files from the directory either. Add $ftp->message() to all the "or die" messages after the connect to get the reason for failure (on connect, $@ gives the reason). E.g.:
    ... or die "cannot list any DIRs " . $ftp->message();
      Thanks, will do!
Re^3: New to Perl: Finding files on FTP
by muppetjones (Novice) on Mar 14, 2012 at 21:00 UTC

    So...I made a mistake. I generally prefer to use array and reference hashes, so shift @{$dir_listing} was out of habit. However, the code I gave actually declared an array so, shift @dir_listing;is the correct way to do it.

    Regarding your comments, the while loop looks at the first element in the array and checks to see if it is just a series of dots using a regex, i.e., either '.' or '..'. If so, it removes the first element and checks again.

    For map, you can think of it as a very specialized foreach loop (map { <expr> } <array>) that returns values depending on the code used in the brackets. However, it is a little slower than a foreach loop so you generally only want to use it when you're using its output. It's a great way to modify or filter out values from an array.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://959645]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2014-10-23 02:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (123 votes), past polls