I have the following script (002.pl) that is generating error messages. Can anyone please give me help?
#! D:\perl\bin
use strict; use warnings;
@now = localtime time; $filename = "Report-" . ($now[4] + 1) . "-" . $now[3]. "-" . $now[5] . "-" . $now[2] . "-" . $now[1] . "-" . $now[0] . ".txt"; print "$filename\n";
Global symbol "@now" requires explicit package name at 002.pl line 6. Global symbol "$filename" requires explicit package name at 002.pl line 7. Global symbol "@now" requires explicit package name at 002.pl line 7. Global symbol "@now" requires explicit package name at 002.pl line 7. Global symbol "@now" requires explicit package name at 002.pl line 7. Global symbol "@now" requires explicit package name at 002.pl line 7. Global symbol "@now" requires explicit package name at 002.pl line 7. Global symbol "@now" requires explicit package name at 002.pl line 7. Global symbol "$filename" requires explicit package name at 002.pl line 8. Execution of 002.pl aborted due to compilation errors.
When you use the 'strict' pragma then you have to declare all of your variables with my() or our().
#! D:\perl\bin
use strict; use warnings;
my @now = localtime;
my $filename = sprintf 'Report-%d-%d-%d-%d-%d-%d.txt', $now[4] + 1, @now[3,5,2,1,0];
print "$filename\n";
Or with the POSIX module.
#! D:\perl\bin
use strict; use warnings; use POSIX 'strftime';
my $filename = strftime 'Report-%m-%d-%y-%H-%M-%S.txt', localtime; print "$filename\n";
John -- use Perl; program fulfillment
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
