For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > March 2005 > Need help creating filename with date









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Need help creating filename with date
Steven Golamco

2005-03-24, 3:56 am

I have the following script (002.pl) that is generating error messages.
Can anyone please give me help=3F
Thanks,
Steve


#! D:\perl\bin

use strict;
use warnings;

@now =3D localtime time;
$filename =3D "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.




_______________
Siebel Systems, Inc.
www.siebel.com

This e-mail message is for the sole use of the intended recipient(s) and =
contains confidential and/or privileged information belonging to Siebel =
Systems, Inc. or its customers or partners. Any unauthorized review, use, =
copying, disclosure or distribution of this message is strictly prohibited.=
=
If you are not an intended recipient of this message, please contact the =
sender by reply e-mail and destroy all soft and hard copies of the message =
and any attachments. Thank you for your cooperation.

Charles K. Clarkson

2005-03-24, 3:56 am

Steven Golamco <mailto:Steven.Golamco@Siebel.com> wrote:

: I have the following script (002.pl) that is generating error
: messages. Can anyone please give me help?

You need to learn about 'my'. You can read about it in the
perlfunc file. There are additional resources linked from there.

Better yet, just go to this page and read it.

http://perl.plover.com/FAQs/Namespaces.html



: #! D:\perl\bin
:
: use strict;
: use warnings;

Great start! Way to go.

:
: @now = localtime time;

my @now = localtime time;


: $filename = "Report-" . ($now[4] + 1) . "-" . $now[3]. "-" . $now[5] .
: "-" . $now[2] . "-" . $now[1] . "-" . $now[0] . ".txt";

Blech!

my $filename =
( join '-', 'Report', $now[4] + 1, @now[3, 5, 2, 1, 0] ) .
'.txt';

: print "$filename\n";


HTH,

Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328

John W. Krahn

2005-03-24, 3:56 am

Steven Golamco wrote:
> 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
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com