title: How to rearrange dates of the month when they span across end of current month to beginning of next month
body: <p>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.</p>
  <pre><code>31 02 28 30 27 01 29 03 04
  </code></pre>
  <p>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</p>
  <pre><code>01 02 03 04 27 28 29 30 31.
  </code></pre>
  <p>To get what I want the script snippet below, does the job and gives</p>
  <pre><code>27 28 29 30 31 01 02 03 04
  </code></pre>
  <p>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.</p>
  <pre><code>my $last_occ=lastidx { /0\d/ } @fdaylist;
  if($last_occ &gt; 1){
    foreach(@fdaylist){
      for(my $mm=$last_occ+1; $mm &lt; @fdaylist; ++$mm){
          push (@fday, $fdaylist[$mm]);
      }
      for(my $nn=0; $nn &lt;= $last_occ; ++$nn){
        push (@fday, $fdaylist[$nn]);
      }
    }
  }
  @fday = uniq(@fday);
  </code></pre>