CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
mkdir based on string?

 



Vincent Jansen
Deleted

Mar 3, 2000, 7:50 AM

Post #1 of 3 (479 views)
mkdir based on string? Can't Post

Hi,

Is it possible to create a directory based on a string?
Because it doesn't seem to work.

My code looks something like this:

$dir = "directory";
mkdir '$dir', 0777;

Thanks.
Vincent


Cure
User

Mar 2, 2000, 10:40 PM

Post #2 of 3 (479 views)
Re: mkdir based on string? [In reply to] Can't Post

Hi Vincent

To create a directory and set it permissions on the directory do the following:


$dir = "directory";
mkdir $dir,"777";
chmod(0777, "$dir");

NOTE: In perl for a literal string use single quotes. For variable interpolation use double quotes.

Cure


darian
Deleted

Mar 3, 2000, 9:26 AM

Post #3 of 3 (479 views)
Re: mkdir based on string? [In reply to] Can't Post

When you put something in single or double quotes Perl takes it as a literal. So with your code:

$dir = "directory";
mkdir '$dir', 0777;

Perl looks at '$dir' just as it is not value of the variable. Try this:

$dir = "directory";
mkdir $dir, 0777;

One thing to remember though is your permissions of 0777 means anyone can access and write to that directory. So before you go put something into production make sure that is what you really want.


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives