zentara has asked for the wisdom of the Perl Monks concerning the following question:
Now here are the two scripts which you put in the top dir at the same level as 1, 2 and 3. The first script when run, will work properly, and make the subdirs 0755 and the test file 0644. The second script,(with warnings on chmod lines) will properly do the subdirs but it makes the test file 0755. What does the warnings do to cause this?
As a second question, why is the recursive chmod so difficult in Perl, where the unix chmod is so simple?
#!/usr/bin/perl -w use strict; use File::Find; my $topdir = shift || '.'; my $filemode = shift || 0644; my $dirmode = shift || 0755; find(\&doit, "$topdir"); #this sub works fine sub doit { return if -d and /^\.\.?$/; chmod($filemode, $_) if (-f $_); chmod($dirmode, $_) if (-d $_); }
#!/usr/bin/perl -w use strict; use File::Find; my $topdir = shift || '.'; my $filemode = shift || 0644; my $dirmode = shift || 0755; find(\&doit, "$topdir"); #this sub causes files to be 0755 instead of 0644 sub doit { return if -d and /^\.\.?$/; chmod($filemode, $_) if (-f $_) or warn $!; chmod($dirmode, $_) if (-d $_) or warn $!; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: File::Find, chmod and warnings
by bart (Canon) on Oct 26, 2003 at 02:51 UTC | |
|
Re: File::Find, chmod and warnings
by etcshadow (Priest) on Oct 26, 2003 at 00:47 UTC | |
by BrowserUk (Patriarch) on Oct 26, 2003 at 01:56 UTC | |
by etcshadow (Priest) on Oct 26, 2003 at 03:20 UTC | |
|
Re: File::Find, chmod and warnings
by hanenkamp (Pilgrim) on Oct 26, 2003 at 02:31 UTC | |
|
Re: File::Find, chmod and warnings
by zentara (Cardinal) on Oct 26, 2003 at 16:18 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |