Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a directory if one doesn't exist using Perl?

Tags:

directory

perl

Currently, my Perl output is hard-coded to dump into the following Unix directory:

my $stat_dir = "/home/courses/" . **NEED DIR VAR HERE**;

The filename is built as such:

$stat_file = $stat_dir . "/" . $sess.substr($yr, 2, 2) . "_COURSES.csv";

I need a similar approach to building Unix directories, but I need to check if they exist first before creating them.

How can I do auto-numbering (revisions) of the $stat_file so that when these files get pumped into the same directory, they do not overwrite or append to existing files in the directory?

like image 526
CheeseConQueso Avatar asked Mar 31 '09 15:03

CheeseConQueso


1 Answers

Remember the directory's -d existence doesn't mean -w writable. But assuming you're in a personal area the mkdir($dir) unless(-d $dir) would work fine.

like image 137
hpavc Avatar answered Sep 19 '22 15:09

hpavc