Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Remote Directory listing

by johnfl68 (Scribe)
on Jul 08, 2012 at 10:23 UTC ( [id://980566]=note: print w/replies, xml ) Need Help??


in reply to Remote Directory listing

OK - I have gotten along much farther now with your help.

I am able to get the list of files from the remote server, and create a local text file with the 10 most recent files.

I just need a little more help. I need to apply a regex (I think) as part of the process, as I need the date and time section each of the 10 file for the next step.

I have this as my last section, giving me the last 10 files in the list:

open(FILE, "<filelist.txt"); @file = <FILE>; chomp @file; close FILE; open (MYFILE, '>links.txt'); print MYFILE "$file[-1]\n"; print MYFILE "$file[-2]\n"; print MYFILE "$file[-3]\n"; print MYFILE "$file[-4]\n"; print MYFILE "$file[-5]\n"; print MYFILE "$file[-6]\n"; print MYFILE "$file[-7]\n"; print MYFILE "$file[-8]\n"; print MYFILE "$file[-9]\n"; print MYFILE "$file[-10]\n"; close (MYFILE);

Can I add something to that, that will use this regex "\d\d\d\d\d\d\d\d\_\d\d\d\d" and print just the portion of the filename that matches for each of the 10 files.

I hope that made sense.

Thanks again everyone for your help!

John

Replies are listed 'Best First'.
Re^2: Remote Directory listing
by aitap (Curate) on Jul 08, 2012 at 10:38 UTC
    Yes, it's possible to match a regex against these strings. Your code can be optimized like this:
    open(FILE, "<filelist.txt"); @file = <FILE>; chomp @file; close FILE; open (MYFILE, '>links.txt'); for my $i (1..10) { print MYFILE "$file[-$i]"; print "$1\n" if $file[-$i] =~ m/(\d{8}_\d{4})/; } close (MYFILE);
    Sorry if my advice was wrong.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-19 03:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found