我想要做的是在指定的位置創建一個文件夾,然後用該日期和用戶名首字母命名該文件夾。我希望用戶能夠在創建文件夾時輸入首字母縮寫。我已經想出瞭如何以正確的格式生成日期,但我需要弄清楚如何將用戶輸入$ initials添加到一起,以便文件夾名稱類似於「130506SS」。我無法弄清楚如何將這兩個變量連接在一起以獲得正確的文件夾名稱。任何人都可以幫我解決這個問題嗎?如何加入兩個變量來創建文件夾名稱?
use strict ;
use warnings ;
use POSIX qw(strftime);
my $mydate = strftime("%y%m%d",localtime(time)); #puts the year month date and time in the correct format for the folder name
print "Enter users initials: ";
my $initials = <STDIN>; # prompts for user input
#$mydate.= "SS"; #stores today's date and the initials
$mydate.= $initials;
sub capture {
my $directory = '/test/' . $mydate;
unless(mkdir($directory, 0777)) {
die "Unable to create $directory\n";
}
}
capture(); #creates the capture folder
sub output {
my $directory = '/test2/' . $mydate;
unless(mkdir($directory, 0777)) {
die "Unable to create $directory\n";
}
}
output(); #creates the output folder
編輯:上述腳本的全部部分工作,除非我試圖加入兩個變量來創建文件夾名稱。 ($ mydate。= $ initials;)我用($ mydate。=「SS」;)測試了它,而腳本完美地工作。我可以設法加入變量$ mydate和一個字符串而不是$首字母。
當你運行你的代碼時,你會得到錯誤消息嗎? – toolic 2013-05-06 19:01:27