Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
There's more than one way to do things
 
PerlMonks  

(MeowChow) Re: -d fails outside the current working directory

by MeowChow (Vicar)
on Jun 05, 2002 at 05:30 UTC ( [id://171772]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to -d fails outside the current working directory

As you see, readdir returns the unqualified names of the directory entries, but -d operates on them within the context of the current working directory, which is a recipe for failure. You should either change your cwd (not really recommended), or prepend the filenames with the relative/absolute path, as in:
print "\nOnly directories:\n", grep { -d "$ARGV[0]/$_" } readdir(DIR);
   MeowChow                                   
               s aamecha.s a..a\u$&owag.print

Replies are listed 'Best First'.
Re: (MeowChow) Re: -d fails outside the current working directory
by Anonymous Monk on Jun 05, 2002 at 06:53 UTC

    Thankyou!

    Excuses:I did read the readdir docs, I am unfortuantely still at the stage where I get lost in the syntax and therefore don't recognise the significance of the sample code;(

    Am I going to get into problems with using paths (abs or rel) when the "user defined path" is actually a relative path derived from the query parameter of an URL and the script will be running in the context of Apache?

      There are serious security issues you need to consider if you allow users to submit their own paths, depending of course on what you're doing with those paths. For the sake of simplicity, I would recommend that you only allow alphanumerics in these path names. You can then properly untaint and scrub your path as follows:
      my $userpath = $CGI->param('userpath'); my $basepath = "C:/wwwroot/whatever"; my $path = join '/', $basepath, $userpath =~ /\w+/g;
      Speaking of untainting, you are using -T, right?
         MeowChow                                   
                     s aamecha.s a..a\u$&owag.print

        No I'm not using -T (yet!).

        Mainly, I suspect, because I have not a clue as to what -T is?

        Currently this is way early in development -- both the script and my knowledge -- but I WILL look into it!

        Thanks for the pointer

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://171772]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.