I am trying to get a list of subdirectories in a given directory using something like the following:
#!/usr/bin/perl -wT use strict; use warnings; use File::Find::Rule; use Data::Dumper; my @subdirs = File::Find::Rule->maxdepth(1)->directory->relative->in('mydir'); print Dumper(@subdirs);
However, running this gives the result:
Insecure dependency in chdir while running with -T switch
I understand that File::Find has options for dealing with taint mode, but I can’t seem to find an equivalent in File::Find::Rule. Is it possible to do the above? Should I use an alternative method for listing subdirectories? Am I completely misunderstanding something obvious that I really should understand about taint mode?
(Edit!) Okay, logic would suggest that throwing in the following would work:
This lets you use the taint-mode features of File::Find by passing arguments directly to that module’s
find()function. Incidentally, File::Find mentions that one should set$untaint_patternby using theqr//operator. For example, the default value isHowever, this does not work! In fact, your issue is a known bug in File::Find::Rule. (For example, here are the CPAN and Debian bug reports.) If you would like a bugfix, then both of those bug reports have patches.
If you are in a restricted environment, one thing you can do is essentially implement the patch yourself in your code. For example, if you want to keep everything in one file, you can add the large code block below after
use File::Find::Rule. Note that this is a very quick fix and may be suboptimal. If it doesn’t work for you (e.g., because you have spaces in your filenames), change the patternqr|^([-+@\w./]+)$|that is used.Note finally that if you want your code organization to be a bit better, you may want to dump this into a separate package, maybe called MyFileFindRuleFix or something, that you always
useafterFile::Find::Ruleitself.