我尝试将${date[0]}
放在我的目录中,该目录相当于01252010
但@hits
未打印。如何设置打开目录以获得所需的输出?感谢。
错误: 在./total.pl第11行第1行包含换行符的文件名不成功。
#!/opt/perl/bin/perl -w
use strict;
open(FH,"/home/daily/scripts/sms_hourly_stats/date.txt");
my @date = <FH>;
print $date[0];
my $path = "/home/daily/output/sms_hourly_stats/${date[0]}/TOTAL.txt";
open(FILE,"$path") or die "Unable to open $path: $!";
my @hits = <FILE>;
print @hits;
close FH;
close FILE;
答案 0 :(得分:5)
您需要删除行结束符号。使用chomp
:
chomp(my @date = <FH>);
答案 1 :(得分:0)
答案 2 :(得分:0)
#!/opt/perl/bin/perl -w
use strict;
open(FH,"/home/daily/scripts/sms_hourly_stats/date.txt");
my @date = <FH>;
my $dir;
print ${date[0]};
chomp($dir = ${date[0]});
my $path = "/home/daily/output/sms_hourly_stats/$dir/TOTAL.txt";
open(FILE,"$path") or die "Unable to open $path: $!";
my @hits = <FILE>;
print @hits;
close FH;
close FILE;