[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] gmtime format in array variable



At 3:45 PM -0500 12/7/00, Mike Hyslop wrote:
>
>#set array for file to copy
>use Time::gmtime;
>$tm3 = gmtime();
>@ftc = 
>("m",($tm3->year+1900,$tm3->mon)+1,($tm3->mday),($tm3->hour-1),(".gz"));
>print @ftc;
>printf("\n");

This is Perl, not C.  gmtime returns a list in array context or a 
single string in scalar context, not a structure pointer.  If you use 
Shuck to look up gmtime, you find this:

	gmtime EXPR

		Converts a time as returned by the time function to a 
9-element array with the time localized for the standard Greenwich 
time zone. Typically used as follows:

   #  0    1    2     3     4    5     6     7     8
   ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
	gmtime(time);

The infix -> does not mean the same thing in Perl as it does in C.

>
>
>The first three portions of the code work as I expected, however the 
>value written to the last array variable does not include zeroes 
>where I expected/hoped it would...  below is the output from perl:
>
>The current file to copy is m0120719.gz
>The correct directory to copy the above file to is 200012
>200012
>m12719.gz
>
>I had hoped to use the array variables as containers for the 
>filenames and destination directories that will change hourly and 
>monthly respectively, and planned to use something like
>
>use File::Copy;
>copy(@ftc, @dtc/@ftc);
>   or die "copy failed: $!";
>
>
>to copy the files once the correct names and destinations were established.
>
>Am I totally off track in my approach here, or is there a way to 
>format the contents of the @ftc variable to include the zeroes I 
>need?  (I also suspect if I were writing this script in January 
>instead of December my month values would be missing the zero I 
>need... I'll adjust my system time to check this).
>
>Any help/hints will be appreciated.
>
>
>Mike Hyslop

-- 
--
Paul Schinder
schinder@pobox.com

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org