Reputation: 159
I tried to placed ${date[0]}
in my directory which is equivalent to 01252010
but @hits
not printed. How can I managed to open the directory to get the desired output? Thanks.
ERROR: Unsuccessful open on filename containing newline at ./total.pl line 11, line 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;
Upvotes: 3
Views: 4636
Reputation: 28713
You need to remove line ending symbol. Use chomp
:
chomp(my @date = <FH>);
Upvotes: 5
Reputation: 67221
#!/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;
Upvotes: 0
Reputation:
Upvotes: 0