Create a file: Difference between revisions

m (Alphabetized entries.)
Line 49:
==[[Perl]]==
[[Category:Perl]]
use File::Spec::Functions qw(catfile rootdir);
sub createNewFile($) {
{ # here
my ($filename) = @_;
test("file" open my $fh, '>', "'output.txt")';
if(-e $filename) { return " already exists."; }
mkdir(" 'docs")';
open(FH, ">> ". $filename) or return " could not be created.";
};
close(FH);
{ # root dir
return " did not exist and was created successfully.";
open my $fh, '>', catfile rootdir, 'output.txt';
}
mkdir catfile rootdir, 'docs';
sub createNewDir($) {
};
my ($filename) = @_;
if(-e $filename) { return " already exists."; }
mkdir($filename) or return " could not be created.";
return " did not exist and was created successfully.";
}
sub test($$) {
my ($type, $filename) = @_;
print "The following " . $type . " called " . $filename .
($type eq "file") ? createNewFile($filename) : createNewDir($filename);
}
my $FileSeperator = ($^O eq "MSWin32") ? "\\" : "/";
test("file", "output.txt");
test("file", $FileSeperator . "output.txt");
test("directory", "docs");
test("directory", $FileSeperator . "docs" . $FileSeperator);
exit;
 
# Short version;
my $FileSeperator = ($^O eq "MSWin32") ? "\\" : "/";
open(FH, ">> output.txt") and close(FH);
open(FH, ">> ".$FileSeperator."output.txt") and close(FH);
mkdir("docs");
mkdir($FileSeperator."docs".$FileSeperator);
 
==[[Tcl]]==
Anonymous user