create directory ...

R

Rickard

Hi,

I am currently setting up an Perl script which will create an directory.

That is not any problem, the problem is that how do i create an
directory out of an variable. Hmm, like this,

my $test = "/tmp/"
my $test2 = "test"

mkpath('$test$test2), 0, 0777);

What i wan´t is to use the values of $test & $test2 to create an directory.

Is that possible?


When i try above i create an directory called $test$test2 instead of
"/tmp/test"


I have read about it at cpan, but no info about how to do it.

//Rickard
 
T

Tim Orbaker

Rickard said:
Hi,

I am currently setting up an Perl script which will create an directory.

That is not any problem, the problem is that how do i create an
directory out of an variable. Hmm, like this,

my $test = "/tmp/"
my $test2 = "test"

mkpath('$test$test2), 0, 0777);

I think you meant:

mkpath( '$test$test2', 0, 0777 );

Your problem is in the quotation. Items encosed in single quotes are
literals. They are not expanded. Use double quotes...

What you need is:

mkpath( "$test$test2", 0, 0777 );
 
J

Jim Cochrane

Hi,

I am currently setting up an Perl script which will create an directory.

That is not any problem, the problem is that how do i create an
directory out of an variable. Hmm, like this,

my $test = "/tmp/"
my $test2 = "test"

mkpath('$test$test2), 0, 0777);

I'm not sure what mkpath is, but I believe what you're asking for is how to
concatenate strings - so you can use the '.' operator:

mkpath($test . $test2, 0, 0777);

If you want portability, you might try using File::Spec.
 
R

Rickard

Tim said:
I think you meant:

mkpath( '$test$test2', 0, 0777 );

Your problem is in the quotation. Items encosed in single quotes are
literals. They are not expanded. Use double quotes...

What you need is:

mkpath( "$test$test2", 0, 0777 );
Then i get following:

Insecure dependency in mkdir while running wit -T switch at
/usr/share/lib/perl5/File/Path.pm at line 133.


Should i run script without -T (perl -wT)

//Rickard
 
R

Rickard

Jim said:
I'm not sure what mkpath is, but I believe what you're asking for is how to
concatenate strings - so you can use the '.' operator:

mkpath($test . $test2, 0, 0777);

If you want portability, you might try using File::Spec.
Are there any other command to use to create an directory?

The thing is that the first variable i use gets its value from an
textfile and the second variable gets it value from an html form.

That is why i want to create an path using these two variables.

Oh, by the way, i use File::path for the mkpath command.

//Rickard Hansson

//Rickard H
 
G

Gunnar Hjalmarsson

Rickard said:
Then i get following:

Insecure dependency in mkdir while running wit -T switch at
/usr/share/lib/perl5/File/Path.pm at line 133.

Should i run script without -T (perl -wT)

If it's a CGI script, doing so would be a bad 'solution'. You'd better
learn from

perldoc perlsec

how to untaint tainted data.
 
J

Jim Cochrane

Are there any other command to use to create an directory?

The thing is that the first variable i use gets its value from an
textfile and the second variable gets it value from an html form.

That is why i want to create an path using these two variables.

Oh, by the way, i use File::path for the mkpath command.

Well, the easy part, concatenating string/scalars together, I suspect
you've figured out.

Creating directories is also quite easy - e.g., system("mkdir $dir"), or
find the right module.

But if you're asking about creating directories in a web-application
context, there are more issues involved. If this is the case, you'll need
to describe precisely what your setup is and what you are trying to do
before people will have enough info. to be able to help you.
 
J

Jim Cochrane

Are there any other command to use to create an directory?
[snippage]

Creating directories is also quite easy - e.g., system("mkdir $dir"), or
find the right module.

What's wrong with the builtin function mkdir?

Nothing. I'm still working on mastering Perl and that one wasn't in my
"database" yet. :)

Using builtin functions is almost always preferable to using 'system', of
course.
 
K

krakle

Jim Cochrane said:
Are there any other command to use to create an directory?
[snippage]

Creating directories is also quite easy - e.g., system("mkdir $dir"), or
find the right module.

What's wrong with the builtin function mkdir?

Nothing. I'm still working on mastering Perl and that one wasn't in my
"database" yet. :)

Well it's a simple command much like the one you were using..
 
G

Guest

Martien Verbruggen said:
What's wrong with the builtin function mkdir?

FWIW, I usually use File::path's mkpath as well. Because:

DESCRIPTION
The "mkpath" function provides a convenient way to create
directories, even if your "mkdir" kernel call won't create more
than one level of directory at a time. "mkpath" takes three
arguments:

No need for me to write code to walk the tree and create
elements as I go - someone else has already done it for me.
 
T

Tad McClellan

FWIW, I usually use File::path's mkpath as well.


You snipped the context.

Martien's comment applied to code that looked like this (ie. not your code):

system("mkdir $dir")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top