get filename using regexp and if

From: Rocky (PerlGuRu2b_at_bobotheclown.org)
Date: 03/18/04


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



Relevant Pages

  • Re: nested loops
    ... Is there a better way to express this than nested loops. ... foreach flowcontrol $flowControls { ... And since you are doing some testing in {script}, ...
    (comp.lang.tcl)
  • Re: Array, foreach problem
    ... I'm stuck on using an array to determine the out come of a foreach loop. ... The script is below. ... Shlomi Fish http://www.shlomifish.org/ ...
    (perl.beginners)
  • Re: looping 2 times through 5000 differs from 5000 times through 2
    ... foreach my $val { ... to see how much overhead there is for each iteration of the loop. ... My script is purely hobby. ... 'uniq' and 'splitline' are subs. ...
    (perl.beginners)
  • foreach statement output
    ... Can anyone explain how to get the output of a foreach statement so it can be ... displayed or used to compare with a variable? ... This script delivers the following lines to the browser: ... have pored over my O'Reilly books and "The Little Black Book" for hours ...
    (comp.infosystems.www.authoring.cgi)