get filename using regexp and if
From: Rocky (PerlGuRu2b_at_bobotheclown.org)
Date: 03/18/04
- Next message: TP: "Help: Deleting Entries in Flat File Database"
- Previous message: Eric Schwartz: "Re: count unique values in array"
- Next in thread: Matt Garrish: "Re: get filename using regexp and if"
- Reply: Matt Garrish: "Re: get filename using regexp and if"
- Reply: John W. Krahn: "Re: get filename using regexp and if"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 18 Mar 2004 21:37:19 GMT
hello everyone
I have a small issue:
here is code that I wrote (please don't make fun of it as I am a newbie)
to get the highest numbered backuplog from a veritas server via ftp:
@filenums = 0;
foreach $file (@files) {
if ($file =~ m/([A-Za-z]{2}X)(\d+)(\.txt)/) {
push(@letter, $1);
push(@filenums, $2);
push(@ext, $3);
$ext = pop(@ext);
}
if ($file =~ m/([A-Za-z]{2}X)(\d+)(\.xml)/) {
push(@letter, $1);
push(@filenums, $2);
push(@ext, $3);
$ext = pop(@ext);
}
}
$letters = pop(@letter);
$highest = (sort { $a <=> $b } @filenums)[-1];
$ftp->get($letters . $highest . $ext) or print FILENAMES $letters . $highest . $ext . "\n";
Please note the last line which prints to a file if it cannot get the file
it wants. I updated the script to get any file modified in the last 24
hours and bearing the extension .txt or .xml (necessary since some of the
servers have two jobs per night)
here is the new code:
$rightnow = time();
[snip]
@filenames = $ftp->ls;
foreach $file (@filenames) {
$time = $ftp->mdtm($file);
$goodfile = $rightnow - $time;
$ftp->get($file) if ($goodfile < "86400" & $file =~ /.*\.txt|.*\.xml/);
the problem:
whenever I add "or print FILENAMES ..." to the last line it gets every file in
the remote dir.
I must have the files missed as I use them in another script. Please help
Thank you,
Rocky Allen
Itried changing it to else but that didn't work either
- Next message: TP: "Help: Deleting Entries in Flat File Database"
- Previous message: Eric Schwartz: "Re: count unique values in array"
- Next in thread: Matt Garrish: "Re: get filename using regexp and if"
- Reply: Matt Garrish: "Re: get filename using regexp and if"
- Reply: John W. Krahn: "Re: get filename using regexp and if"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|