in reply to Re^2: Rolling variable
in thread Rolling variable

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.

Replies are listed 'Best First'.
Re^4: Rolling variable
by stevieb (Canon) on Jul 30, 2015 at 14:37 UTC

    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.

        The OP did not say he needed to keep a list of files. The OP stated that the count of files is all that was wanted.