Rudif has asked for the wisdom of the Perl Monks concerning the following question:
... that decides to accept or reject a file, based on the extension and on file tests. A .bat file being a -f, -T and -x, it should be accepted, from reading above unless clause.sub _check_and_extract_name { my ($file, $verbose, $root_rx) = @_; # check extension or executable flag # this involves testing the .bat extension on Win32! unless(-f $file && -T _ && ($file =~ /\.(pod|pm|plx?)\z/i || -x _ +)) { return undef; } return undef unless contains_pod($file,$verbose); # ... proceed with adding the accepted file to the lost of pods .. +.
I experimented some more and found that the malfunction of -x _ occurs inside a logical expression, but not in a series of simple statements. The script below demonstrates these findings.# change the order of terms in && expression unless(-f $file _ && ($file =~ /\.(pod|pm|plx?)\z/i || -x _ ) && - +T) { return undef; # replace the _ variable by $file unless(-f $file && -T _ && ($file =~ /\.(pod|pm|plx?)\z/i || -x $f +ile )) { return undef;
#!perl -w use strict; use Pod::Find; # # Test Pod::Find::pod_find on C:/perl/bin # my $dir = 'C:/perl/bin'; my %pods = Pod::Find::pod_find({ -verbose => 1}, $dir); my @pods = keys %pods; my $n = keys %pods; printf "Found $n files containing pods: @pods\n"; printf "NOTE 1: above finds .pl but not .bat files containing pods\n\n +"; # # Test using _ variable in filestests # my $bat = 'c:/perl/bin/pod2html.bat'; my $exe = 'c:/perl/bin/perl.exe'; filetest ($bat); filetest ($exe); printf "NOTE 2: above shows that -x _ basically works as advertized\n\ +n"; sub filetest { my $file = shift; print "$file: "; stat($file); print " Readable" if -r _; print " Writable" if -w _; print " Executable" if -x _; print " Text" if -T _; print " Binary" if -B _; print "\n"; } # # Demo the bug and workarounds # # simplified from Pod::Find, -x _ does not work printf "1 $bat ok for pod: %d\n", (-f $bat && -T _ && -x _); # 4 workarounds printf "2 $bat ok for pod: %d\n", (-f $bat && -x _ && -T _); printf "3 $bat ok for pod: %d\n", (-f $bat && -x $bat && -T _); printf "4 $bat ok for pod: %d\n", (-f $bat && -T _ && -x $bat); printf "5 $bat ok for pod: %d\n", (-f $bat && -T $bat && -x $bat); printf "NOTE 3: above shows that -x _ does not work as advertized in c +ase 1\n\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem with filetest -x _ on Win2k AS Perl build 626
by bikeNomad (Priest) on Jun 25, 2001 at 00:44 UTC | |
by Rudif (Hermit) on Jun 25, 2001 at 03:15 UTC | |
by bikeNomad (Priest) on Jun 25, 2001 at 04:08 UTC | |
|
Re: Problem with filetest -x _ on Win2k AS Perl build 626
by Rudif (Hermit) on Jun 26, 2001 at 17:31 UTC | |
by Rudif (Hermit) on Jul 01, 2001 at 21:45 UTC |