Steven Shoemaker wrote:
Hi,

Hello,

What am I doing wrong? And yes I know that there is a module for chmod but it is not loaded on this server that I need to run this on.

The assumption here is that your code is not working correctly but you have not explained exactly what it is supposed to do so I will have to guess. It looks like you might have used find2perl to create this program?



use warnings;

use strict;
use File::Find ();

Using empty parentheses means that you don't want to import anything from the module File::Find.


*name = *File::Find::name;
>
File::Find::find({\&FixMode}, '.');

The first argument to File::Find::find() is either a reference to a subroutine or a reference to a hash. You are passing an anonymous hash (a hash reference) with a single key (a sub reference) and no value which will produce an error.


exit;

sub FixMode {
   my ($dev,$ino,$mode,$nlink,$uid,$gid);
   my ($nmode,$omode);

(($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) && -f _ &&

You are only using the $mode variable so there is no need to declare all the others.


    ((($mode & 02) == 02) || (($mode & 020) == 020)) &&
    chmod sprintf("0%o", ($mode &  0755)), $name;

perldoc -f chmod chmod LIST Changes the permissions of a list of files. The first element of the list must be the numerical mode, which should probably be an octal number, and which definitely should not a string of octal digits: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 0644 is okay, '0644' is not. Returns the number of files successfully ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ changed. See also "oct", if all you have is a string.


You need to pass a *number* to chmod, not a string. Also the variable $name was not declared (anywhere that I can see.)

You probably want something like this:

use warnings;
use strict;
use File::Find;

find( \&FixMode, '.' );
exit 0;

sub FixMode {
    my $mode;
    $mode = ( lstat )[ 2 ]
    and -f _
    and ( ( $mode & 02 ) == 02 or ( $mode & 020 ) == 020 )
    and chmod( ( $mode & 0755 ), $_ )
    }

__END__


John -- use Perl; program fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to