[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [Sheflug] Slightly OT :perl file exists test
On Wed, 2004-05-12 at 13:09, Chris Johnson wrote:
> Thanks to everyone that sent in the code and I apologise for
> not looking a) on google and b) on pageresource first.
I think a further apology for not knowing/using perlmonks.org is also in
order ;o)
> Is there any benefit to using -e (file exists ) over -f (file is a plain
> file (what is a plain file?)?
Yeah, they do different things - -e is 'any type of file exists'. -f
means is a plain file, as opposed to device file, or pipe, or similar
strange thing. Most files are plain files ;)
In this instance I would probably -f; since a file cannot be a plain
file if it doesn't exist.
> If I test the file and it doesn't exist is there a quick and easy way of
> creating the directory structure the file is in if the directories don't
> exist as well, like a
> mkdir --parents /home/httpd/cgi-bin/myscripts/newscripts/currentscripts
use File::Path qw( mkpath );
$path = '/home/httpd/cgi-bin/myscripts/newscripts/currentscripts';
mkpath($path, 0, 0755); # last number is perms, you may want different.
> If I test for ./myscripts/newscripts/currnetscripts/thisscript.pl and it
> doesn't exist I want to create a link that will run a script to create the
> directory structure and an empty file called thisscript.pl and then call
> another script to allow the editing of the file.
That sounds like a horrible security hole :)
Cheers,
Alex.
___________________________________________________________________
Sheffield Linux User's Group -
http://www.sheflug.co.uk/mailfaq.html
GNU the choice of a complete generation.