
s660117
Novice
Jul 6, 2010, 10:34 AM
Post #1 of 5
(714 views)
|
|
-x file tests failing
|
Can't Post
|
|
Hi, I have a little Perl script that I wrote as an exercise. It is a variation on grep that searches subfolders as well as the current directory. This script works fine on Windows, but I'm having a problem under Suse with the statement that checks to see if the current directory is a symlist or is equal to "dev". The script follows - #! /usr/bin/perl -w if (@ARGV) {($dir,$str) = @ARGV;} -d $dir || die "Terminating. $!"; print "Now scanning $dir for \"$str\"\n"; $currdir = $dir; chdir ($currdir) || die "Failed to chdir to $currdir. $!"; while ($dirent = <*>) { if ($dirent =~ /^$str/) {print "$dirent found in $currdir\n";} if (-d "$dirent" && !(-l "$dirent") && $dirent ne "dev") { srchdir(); # chdir '..' || die "Chdir .. failed $!";; chomp($currdir = `pwd`); } } sub srchdir { $currdir = "$currdir"."\/"."$dirent"; chdir ("$dirent") || die "Chdir .. failed. $!"; while ($dirent = <*>) { if ($dirent =~ /^$str/) {print "$dirent found in $currdir\n";} if (-d "$dirent" && !(-l "$dirent") && $dirent ne "dev") { srchdir(); # chdir '..' || die "Chdir .. failed $!"; chomp($currdir = `pwd`); } } } If I run the script against /usr, for example, looking for a file that exists in /bin, it finds it and prints a message to that effect. It fails, however, to look in any subsequent directories such as /include because the statement if (-d "$dirent" && !(-l "$dirent") && $dirent ne "dev") { then resolve to false. If I put in some diagnostic checks - $directory = "$currdir"."\/"."$dirent"; if (-e "$directory") {print " $directory exists\n";} else {print " $directory does not exist\n";} if (-d "$directory") {print " $directory is a directory\n";} else {print " $directory is not a directory\n";} if (!(-l "$directory")) {print " $directory is not a symlist\n";} if ($dirent ne "dev") {print " $directory is not dev\n";} I get the following using /include as an example - /usr/bin/include does not exist /usr/bin/incdlue not a directory /usr/bin/include is not a symlist /usr/bin/include is not dev. And for /tmp, which is a symlist, I get - /usr/bin/tmp does not exist /usr/bin/tmp is not a directory /usr/bin/tmp is not a symlist /usr/bin/tmp is not dev. I don't understand why the -x file tests are failing and would appreciate any help in this matter. Thanks, s660117
|