in reply to File::Find, chmod and warnings

"doh!!!"...As usual when I post a question on a Saturday night my brain isn't at 100%......I knew what the problem was when I woke up this morning. Its funny how sleep can clarify things. The problem as I see it, is the precedence of "if" and "or" when using that "trailing if" idiom. So when I added the "or warn", the statement

chmod($dirmode, $_) if (-d $_) or warn $!;

if (-d $_) or warn $!;

would always return true, since warn is always there, and everything, both files and directories were made 0755. My solution is (without Bart's correct fixes about octal() ) :

#!/usr/bin/perl -w use strict; use File::Find; my $topdir = shift || '.'; my $filemode = shift || 0644; my $dirmode = shift || 0755; find(\&doit, "$topdir"); sub doit { return if $_ eq "." or $_ eq ".."; if(-f $_){chmod($filemode, $_)or warn $!} if(-d $_){chmod($dirmode, $_) or warn $!} }