이 스크립트를 작성하여 스크립트를 실행하는 사용자의 기본 웹 사이트를 만들었습니다. 그것은 Windows 또는 유닉스 시스템에서 할 수 있지만, 어떤 이유로 파일이 열리지 않습니다.Windows의 Perl이 파일을 열 수 없음
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
#createSite.pl
#Attributes
my $sys;
my $user;
my $site;
my $cgistuff = CGI->new;
#Subroutine for checking system.
sub checkSys {
if ($ARGV[0] eq "-w") {
$sys = "\\";
} elsif ($ARGV[0] eq "-l") {
$sys = "/";
} else {
print "System not defined please use -w or -l flag for Windows or Linux\n\n";
}
#Obtains user name based on user input.
print "What would you like your user name to be: ";
$user = <STDIN>;
chomp($user);
$user = lc($user);
#Obtains site name based on user input.
print "What would you like your site/domain to be called: ";
$site = <STDIN>;
chomp($site);
$site = lc($site);
#Debug for printing user name and site name
print "Username: $user, Site/Domain: $site\n";
#After checking what system the user is on create file structure.
createFS();
}
#Subroutine for file structure creation.
sub createFS {
my $rootDir;
if ($sys eq "\\") {
$rootDir = 'mkdir ' . 'C:\\inetpub\\wwwroot\\~' . $user . $sys;
} elsif ($sys eq "/") {
$rootDir = 'mkdir /var/www/html/~' . $user . $sys;
}
system($rootDir);
picDir();
databaseDir();
mailDir();
createPage();
}
#Subroutine to create use OBwebsite.
sub createPage {
if ($sys eq "\\") {
system("echo> C:\\Inetpub\\wwwroot\\~" . $user . "\\index.html");
open(WEBFILE, ">", "C:\\Inetpub\\wwwroot\\~" . $user . "\\index.html")
or die "index.html could not be opened.\n";
} elsif ($sys eq "/") {
system("touch /var/www/html/~" . $user . "/index.html");
open(WEBFILE, ">", "/var/www/html/~" . $user . "/index.html")
or die "index.html could not be opened.\n";
}
print WEBFILE $cgistuff->start_html(), $cgistuff->h1("Welcome $user!!!"), $cgistuff->end_html;
close WEBFILE;
}
#Subroutine for creation of Pictures Directory.
sub picDir {
my $picDir;
if ($sys eq "\\") {
$picDir = 'mkdir C:\\Inetpub\\wwwroot\\~' . $user . '\\pictures';
} elsif ($sys eq "/") {
$picDir = 'mkdir /var/www/html/~' . $user . '/pictures';
}
system($picDir);
}
#Subroutine for creation of Database Directory.
sub databaseDir {
my $dbDir;
if ($sys eq "\\") {
$dbDir = 'mkdir ' . 'C:\\Inetpub\\wwwroot\\~' . $user . '\\database';
} elsif ($sys eq "/") {
$dbDir = 'mkdir /var/www/html/~' . $user . '/database';
}
system($dbDir);
}
#Subroutine for creation of Mail Directory.
sub mailDir {
my $mailDir;
if ($sys eq "\\") {
$mailDir = 'mkdir C:\\Inetpub\\wwwroot\\~' . $user . '\\mail';
} elsif ($sys eq "/") {
$mailDir = 'mkdir /var/www/html/~' . $user . '/mail';
}
system($mailDir);
}
#Actions happen here.
checkSys();
스택 오버플로가 숙제를 넣을 장소가 아니라는 것을 알고 있지만 왜 이런 식으로 작동하지 않는지 잘 모르겠습니다.
을 추천합니다! ' :'my $ fh ','<', $ file 또는 die "$ file : $!";'일반적으로 어휘 파일 핸들 (예 :'my $ fh')과' 내가 여기서했던 것처럼. – ThisSuitIsBlackNot