http://www.perlmonks.org?node_id=317025


in reply to simple chmod

The code itself looks OK. First, you can examine chmod's return value. Manual says that it returns the number of successfully chmod'ed files. So you can do something like:

chmod $mod, $file or die "Couldn't chmod $file";

Then you can check if you have enough permissions to change attributes of the file. If you want to incorporate this checks into your program, then read the "perldoc -f -X".

HTH.

Replies are listed 'Best First'.
Re^2: simple chmod (better error messages)
by Aristotle (Chancellor) on Dec 26, 2003 at 04:55 UTC
    chmod $mod, $file or die "Couldn't chmod $file";
    A good suggestion, but lacking. If you add just five or so characters you get something much more useful:
    chmod $mod, $file or die "Couldn't chmod $file: $!\n";
    That will probably reveal the reason for the chmod failure without requiring any further investigation.

    Makeshifts last the longest.

      Actually, that is what I was writing, but didn't finish for some reason. :)
      I guess I need more sleep rather then more of these NOC shifts. :)