in reply to chmod in perl script

You do use chmod, but you have to keep in mind that unlike the command-line chmod, which can simply flip bits on or off, perl's chmod sets the entire permission set as a single unit. Basically, you have to read the current permissions off the file using stat, add group sticky to those permissions bitwise, and then apply the new permissions using chmod. I think the group sticky bit is 02000, so that'd be:
my $filename = 'filename'; my $perms = ((stat($filename))[2] & 07777); # Just permissions, not + type my $newperms = $perms ^ 02000; # Add the group sticky +bit chmod $newperms, $filename or die "Could not change permissions: $!";

Replies are listed 'Best First'.
Re^2: chmod in perl script
by mcleary (Initiate) on Feb 08, 2011 at 19:09 UTC

    Thanks a lot Monks!

    I wound up using bellaire's suggestion and it worked perfectly.

    Take care, Michele