in reply to Rolling variable
I would need to keep that counts somewhere for another calculation but I would like to keep only the last 8 counts
If the script is being executed each hour (presumably via a cron job) and you need to retain/use the array from the prior run, then you might want to look at using the Storable module to store/retrieve the array.
Update:
Just in case you weren't sure what I was suggesting, here's a short test script example.
use strict; use warnings; use Storable qw(store retrieve); my @cnt = -e 'file_count' ? @{ retrieve('file_count') } : ('') x 8; my $fcount; $fcount++ for glob('*'); unshift @cnt}, $fcount; pop @cnt; store(\@cnt, 'file_count');
Edit: changed the array reference $cnt_aref to a plain array @cnt
|
|---|