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

Re: [MacPerl] Time question



At 11:37 am -0800 6/1/00, Enrique Terrazas wrote:

>Your script can be written a little more succinctly (and I think a little
>more readable):
>
>     #!perl -w
>     use strict;
>     my ($mday, $mon, $year) = (localtime(time))[3..5];
>     $year = $year + 1900;
>     $year = substr $year, 2;
>     print sprintf "\n%02u/%02u/%02u", $mon + 1, $mday, $year;

Yes, thanks.  I've learned a lot from that and especially the power 
of sprintf.  It also seems a good idea for me to 'use strict' while 
I'm learning.

I've now elaborated this to make a little routine to confirm the 
saving of a temporary file


        #!perl -w
        use strict;
        my ( @time, $timestamp, $save) = (localtime time);
        my ($year, $mon, $mday, $hour, $min, $sec) =
             @time[5,4,3,2,1,0];
        $year = $year + 1900;
        $year = substr $year, 2;
        $timestamp =  sprintf
           qq(temp%02u%02u%02u_%02u%02u%02u\.txt),
             $year, $mon + 1, $mday, $hour, $min, $sec ;
        $save = MacPerl::Answer
           ("\nSave as\n\n$timestamp \?","Save", "Cancel");
        if ($save)
                 {print "\a"}

JD




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