I’m trying to add a datestamp to my output files using perl. What I’m getting is a strange ‘?’ appended to the time stamp for a logfile.
Output file: abcdump-20110120?.log
And the other strange behavior is that my code won’t name my output file with a .csv extension where I am using my $dt (date) variable $node-$tblist.$dt.csv
Output file: foo-p000.20110120
But, If I remove $dt from the naming convention $node-$tblist.csv
it will work: foo-p000.csv
It must be how I am trying to create my datestamp.
Code:
my $dt = `date '+%Y%m%d'`;
open (LOG, "> abcdump-$dt.log") || die "cannot append";
foreach my $tblist (@tblist)
{
chomp $tblist;
my $crfile = qq{mysql -u test -pf00 --database $dbsrc -h $node -ss -e "SELECT 'a','b','c' UNION SELECT 1,2,3 FROM $tblist"| tr "\t" ",">$node-$tblist.$dt.csv};
system($crfile);
print LOG "Executed on $dt => $crfile\n";
};
close(LOG);
Ignoring the other issues in your code, I suspect it’s a newline as part of the
dateoutput.should take care of both of the problems you describe.
You may also wish to consider using Perl’s
localtimeorgmtimeinstead.