Just a small snip to rotate logfiles... The files are in the directory with a prefix (file) and a number appended file.1 file.2 file.3 .... This will take the files and rotate them to the next greatest number upto the set history size. I'am sure that it can be done shorter/quicker .. but it's a start!

UPDATE: cleaned up code using blazar's comments
use strict; use warnings; my $log_dir = "dir"; my $log_pre = "file"; my $hist_size = 10; foreach(sort {($b =~ m/(\d+)$/)[0] <=> ($a =~ m/(\d+)$/)[0]} <$log_dir +/$log_pre.*>){ my $f=$_; s/(\d+)$/$1+1/e; if($1 >= $hist_size){ unlink $f; }else{ rename $f,$_; } }

In reply to Rotating Log Files by aukjan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.