in reply to Re: Problem with renaming files in directory
in thread Problem with renaming files in directory

ok, thanks for replies guys :) Right now my code is:
foreach my $filename (reverse((grep /^sniffer/, <*>))) { my $new_name = $filename; if($new_name =~ m/(\d+)/) { my $value = $1 +1; $new_name = "sniffer$value.log"; } else { $new_name = "sniffer1.log"; } rename($filename, $new_name) unless $filename eq $new_name; }

I didn't run with -T switch and I have all the time the error. Do you have any other hints ? :)

Replies are listed 'Best First'.
Re^3: Problem with renaming files in directory
by toolic (Bishop) on Jan 03, 2012 at 16:42 UTC
    Using diagnostics reveals this info:
    Insecure dependency in rename while running with -T switch at (F) You tried to do something that the tainting mechanism didn't l +ike. The tainting mechanism is turned on when you're running setuid or setgid, or when you specify -T to turn it on explicitly. The tainting mechanism labels all data that's derived directly or indi +rectly from the user, who is considered to be unworthy of your trust. If + any such data is used in a "dangerous" operation, you get this error. + See perlsec for more information. Uncaught exception from user code: Insecure dependency in rename while running with -T switch at
    Since you are not explicitly using -T, look into setuid or setgid.

    By the way, changing readdir to glob will not solve the double-digit filename issue.

      So what should I do solve this double-digit filename issue ?:)

      I run this script as a root and I found that perl create those files with user id 200. I don't have user with this id. So for me is this strange. The group id for this file is the root, so everything is ok. If anyone know why I have user id 200 instead of 0 ?

        So what should I do solve this double-digit filename issue ?:)
        You already know how to grab the digits using a regex. Now you need to create an array of filenames and sort them numerically:
        perldoc -q sort