我想要做的是在指定的位置创建一个文件夹,然后用该日期和用户名首字母命名该文件夹。我希望用户能够在创建文件夹时输入首字母缩写。我已经想出了如何以正确的格式生成日期,但我需要弄清楚如何将用户输入$ 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