subroutine references



I'm working on yet another exercise from Intermediate Perl. I've been
given a script that searches for files that fall between a two
timestamps. For the exercise, I am supposed to write the
gather_mtime_between subroutine that will return two references to two
subroutines. One will use File::Find that will find the files that
were modified between the two timestamps. The other function should
return a list of the found items.

use strict;

use File::Find;
use Time::Local;

sub gather_mtime_between {
return (
sub {
foreach my $filename(my @file_list){
my $timestamp = (stat $filename)[9];
if (my $start <= $timestamp <= my $stop){
push @found_items, $filename;
}
}
},
sub { return @found_items };
)
}

my $target_dow = 1; # Sunday is 0, Monday is 1, ...
my @starting_directories = (".");

my $seconds_per_day = 24 * 60 * 60;
my($sec, $min, $hour, $day, $mon, $yr, $dow) = localtime;
my $start = timelocal(0, 0, 0, $day, $mon, $yr); # midnight today
while ($dow != $target_dow) {
# Back up one day
$start -= $seconds_per_day; # hope no DST! :-)
if (--$dow < 0) {
$dow += 7;
}
}
my $stop = $start + $seconds_per_day;

my($gather, $yield) = gather_mtime_between($start, $stop);
find($gather, @starting_directories);
my @files = $yield->();

for my $file (@files) {
my $mtime = (stat $file)[9]; # mtime via slice
my $when = localtime $mtime;
print "$when: $file\n";
}

I have 3 questions:
1) The $start and $stop variables in my subroutine are the $start and
$stop variables in the script at large. However, I had to label these
with 'my' because I was getting error messages. Will this cause
trouble?

2) How do I get the array @starting_directories into my first
anonymous subroutine? I need @starting_directories to be in the same
place as @file_list.

3) When I run the script I get these error messages:
syntax error at last_mod.pl line 16, near "$timestamp <="
syntax error at last_mod.pl line 20, near "}"
I can't figure out what is causing these error messages. The various
braces, etc. seem to match up.

.



Relevant Pages

  • Re: What is the need for @ symbol in php script
    ... The '@' just suppresses error messages, which is never a good idea ... A fatal error will ALWAYS stop your script from working - that's why ... Hardly cumbersome, compared to managing code with list, and ... extractfunction makes the process easier. ...
    (comp.lang.php)
  • Re: IE Wont Open
    ... notification about every script error." ... Open Internet Explorer. ... Two download versions are available for Windows Script 5.6. ... please post back to this thread with the details and any error messages. ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: IE Crashes when loading page with javascript
    ... See these articles for possible help w/ error messages in scripting: ... Error Message When You Browse the Web: An Error Has Occurred in the Script ... Windows Script 5.7 for Windows XP ... updates/security roll-ups, etc. from Windows Update. ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: IE Crashes when loading page with javascript
    ... See these articles for possible help w/ error messages in scripting: ... Error Message When You Browse the Web: An Error Has Occurred in the Script ... Windows Script 5.7 for Windows XP ... updates/security roll-ups, etc. from Windows Update. ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: Logon Scripts for Dept. and Printers based on Groups and IP
    ... I have a script that was put together by a several different scripts ... error messages and report them to me so I can fix them. ... Our logon script logs its proceedings and error messages into a file in the ... Having some drives pre-assigned is therefore not ...
    (microsoft.public.scripting.vbscript)