in reply to Re: Rolling variable
in thread Rolling variable

Hi James, Rata, Thanks for the inputs. However, I thin k this will work in a single run of the script (please correct me if I'm wrong). Since I would like to monitor in an hourly basis, that means I will call the perl script to run thru a cron. So I was thinking to save the counts in a file.

Replies are listed 'Best First'.
Re^3: Rolling variable
by james28909 (Deacon) on Jul 30, 2015 at 14:05 UTC
    you could easily adopt this into a script and have it run every hour. call it from your main script. spit any output to files if needed. go ahead modify it as needed :)))
Re^3: Rolling variable
by james28909 (Deacon) on Jul 30, 2015 at 14:18 UTC
    use strict; use warnings; my @file_array = qw(file1 file2 file3 file4 file5 file6 file7 file8 fi +le9); my @reversed_file_array = reverse @file_array; my @files; while (1) { for ( 0 .. 7 ) { push @files, $reversed_file_array[$_]; } print "$_\n" for @files; undef @file_array; undef @files; sleep 2; #or sleep 3600 for 1 hour }
    If you dont undef @files then it will keep a list of the filenames. You can comment it out to see if you need to undef it or not. To me though, if you have already did operations on the files in @files, then there is no need to save a list.

      This does not solve the prerequisite that the OP needs to access the list of file counts from an external source in between runs.

      Also, there's no reason to have to use so many arrays and trickery. The following will remove the oldest addition after the array reaches a length of eight, and add a new one to the bottom of the list:

      my @a = qw(1 2 3 4 5); for (1..5){ shift @a if @a == 8; push @a, 'new data'; } print "$_\n" for @a;
        Thanks, i will def keep that in mind. Honestly all i was trying to do was give some ideas. I didnt see anyone else post yet and was just giving ideas.
        EDIT: Also, the list of files could easily be written to a static spot in the file system.