Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 109747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:07:05+00:00 2026-05-11T02:07:05+00:00

I am trying to get a list of subdirectories in a given directory using

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T02:07:06+00:00Added an answer on May 11, 2026 at 2:07 am

    (Edit!) Okay, logic would suggest that throwing in the following would work:

    ->extras( {untaint => 1, untaint_pattern => $untaint_pattern, untaint_skip => 1} ) 

    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_pattern by using the qr// operator. For example, the default value is

    $untaint_pattern = qr|^([-+@\w./]+)$| 

    However, 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 pattern qr|^([-+@\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 use after File::Find::Rule itself.

    package File::Find::Rule; no warnings qw(redefine); sub in {     my $self = _force_object shift;      my @found;     my $fragment = $self->_compile( $self->{subs} );     my @subs = @{ $self->{subs} };      warn 'relative mode handed multiple paths - that's a bit silly\n'       if $self->{relative} && @_ > 1;      my $topdir;     my $code = 'sub {         (my $path = $File::Find::name)  =~ s#^(?:\./+)+##;         $path = '.' if ($path eq ''); # See Debian bug #329377         my @args = ($_, $File::Find::dir, $path);         my $maxdepth = $self->{maxdepth};         my $mindepth = $self->{mindepth};         my $relative = $self->{relative};          # figure out the relative path and depth         my $relpath = $File::Find::name;         $relpath =~ s{^\Q$topdir\E/?}{};         my $depth = scalar File::Spec->splitdir($relpath);         #print 'name: \'$File::Find::name\' ';         #print 'relpath: \'$relpath\' depth: $depth relative: $relative\n';          defined $maxdepth && $depth >= $maxdepth            and $File::Find::prune = 1;          defined $mindepth && $depth < $mindepth            and return;          #print 'Testing \'$_\'\n';          my $discarded;         return unless ' . $fragment . ';         return if $discarded;         if ($relative) {             push @found, $relpath if $relpath ne '';         }         else {             push @found, $path;         }     }';      #use Data::Dumper;     #print Dumper \@subs;     #warn 'Compiled sub: '$code'\n';      my $sub = eval '$code' or die 'compile error '$code' $@';     my $cwd = getcwd;     # Untaint it     if ( $cwd =~ qr|^([-+@\w./]+)$| ) {         $cwd = $1;     } else {         die 'Couldn't untaint \$cwd: [$cwd]';     }     for my $path (@_) {         # $topdir is used for relative and maxdepth         $topdir = $path;         # slice off the trailing slash if there is one (the         # maxdepth/mindepth code is fussy)         $topdir =~ s{/?$}{}           unless $topdir eq '/';         $self->_call_find( { %{ $self->{extras} }, wanted => $sub }, $path );     }     chdir $cwd;      return @found; } use warnings; package main; 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 70k
  • Answers 70k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer If you have a saw and you need to pound… May 11, 2026 at 12:49 pm
  • added an answer Did you call GdiplusStartup before creating the Bitmap? May 11, 2026 at 12:49 pm
  • added an answer Refer to DATE_FORMAT() function in MySQL. I guess that's the… May 11, 2026 at 12:49 pm

Related Questions

I am trying to get a DataGrid under CE 5.0 / .NET CF 2.0
I am trying to get a definitive answer regarding the way COM behaves on
I am trying to get a simple demo started with ActiveMQ that will demonstrate
I am trying to get a MethodInfo object for the method: Any<TSource>(IEnumerable<TSource>, Func<TSource, Boolean>)
I am trying to match multiple CSS style code blocks in a HTML document.
I am trying to make the Validation plugin work. It works fine for individual
I am having some issues with getting the list of parents of an element
I am using VMware Workstation 6.5 on Windows Vista x64. I am trying to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.