I have to work on data which goes according to dates of the month. When I extract the dates from the filename I get a random arrangement of the dates, as below.
31 02 28 30 27 01 29 03 04
This is processing the data from 27th August to 4th September. I need the dates arranged sequentially from 27th to 4th. I have to process 9 dates at a time. This problem arises at the end of the month when I have this month's dates (large figures) and next month (small figures).So I sort the array which I call @fdaylist. I get
01 02 03 04 27 28 29 30 31.
To get what I want the script snippet below, does the job and gives
27 28 29 30 31 01 02 03 04
I am sure if this script can work all the time. It reproduces the sequence several time over, so I have to use the uniq() function. I will appreciate if I can get a suggestion of a better way of achieving my objective.
my $last_occ=lastidx { /0\d/ } @fdaylist;
if($last_occ > 1){
foreach(@fdaylist){
for(my $mm=$last_occ+1; $mm < @fdaylist; ++$mm){
push (@fday, $fdaylist[$mm]);
}
for(my $nn=0; $nn <= $last_occ; ++$nn){
push (@fday, $fdaylist[$nn]);
}
}
}
@fday = uniq(@fday);