lina wrote:
Hi,
Hello,
At some directory, I wish to check are there some new file generated with step* if no new generated, I wish it sleep for a while if there are some new files generated, I wish it to send am email to myself. Here is what I have came up so far, #!/usr/bin/env perl use strict; use warnings; use 5.012; use File::Glob ':glob'; use Time::HiRes qw(sleep); use Mail::Sendmail; my $old_num = 1; my $new_num; while($old_num< 100){ checkfile(); if ($new_num == $old_num){ sleep(0.1); } if ($new_num != $old_num){ $old_num = $new_num; sendmail(); } } sub checkfile{ my @filelist = bsd_glob("step*"); my $new_num = scalar(@filelist); }
You don't change the value of $new_num inside the while loop so you should probably do this instead:
my $old_num = 1; while ( $old_num < 100 ) { my $new_num = checkfile(); if ( $new_num == $old_num ) { sleep( 0.1 ); } else { $old_num = $new_num; sendmail(); } } sub checkfile { my @filelist = bsd_glob("step*"); return scalar @filelist; } John -- Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction. -- Albert Einstein -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/