for (...) { push @a, $_; }
is a long way of doing
push @a, ...;
Depending on the context, it might make more sense to do just
my @a = ...;
unless ( ($localtimenoformat - $mdtmnoformat) > 3600 ) {
can more clearly be written as
if ( ($localtimenoformat - $mdtmnoformat) <= 3600 ) {
$localtimenoformat=time; doesn't need to be executed multiple times.
What you call "no format" time could really be called "epoch" time.
push @files, $ftp->ls; my $new_file = 0; my $current_time_epoch = time; for my $file (@files) { my $modified_time_epoch = $ftp->mdtm($file); if ( ($current_time_epoch - $modified_time_epoch) <= 3600 ) { print "$file\n"; print "Current time = $current_time_epoch\n"; print "MDTM = $modified_time_epoch\n"; $new_file = 1; } } envia_mail() if !$new_file; $ftp->quit or die $ftp->message;
If those print statements are just for debugging purposes, you can exit the loop early.
push @files, $ftp->ls; my $new_file = 0; my $current_time_epoch = time; for my $file (@files) { if ( ($current_time_epoch - $ftp->mdtm($file) ) <= 3600 ) { $new_file = 1; last; } } envia_mail() if !$new_file; $ftp->quit or die $ftp->message;
In reply to Re^2: Newbie: need algorithm to evaluate no file exist
by ikegami
in thread Newbie: need algorithm to evaluate no file exist
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |