Hi, I need a help with renaming files which begins "sniffer" in directory.
opendir(DIR, '.') || die "Couldn't opendir: $!\n"; foreach my $filename (reverse((grep /^sniffer/, readdir(DIR)))) { my $new_name = $filename; if($new_name =~ m/(\d+)/) { my $value = $1 +1; $new_name =~ s/.*/"sniffer$value\.log"/; } else { $new_name =~ s/.*/sniffer1.log/; } rename($filename, $new_name) unless $filename eq $new_name; close(DIR);

My aim is to increment number in files which begin "sniffer". In example: sniffer.log will be sniffer1.log, sniffer1.log will be sniffer2.log, etc. The oldest file (with the highest number) must be changed at the beginning - this is the reason of using reverse function in foreach loop.

Unfortunately I received this error:

Insecure dependency in rename while running with -T switch at ...

If anyone knows the solution of this problem or the easiest way how to increment files number ?

Thanks in advance ;)

In reply to Problem with renaming files in directory by ice_ice_ice

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.