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

Re: [MacPerl] MPW crash with perl tool and MacPerl::DoAppleScript



At 16.57 1998.02.09, D. Beverly wrote:
>     What's this for, anyway?  Why not use MacPerl time functions?
>Quick... what day of the week was March 15, 1925?  What weekday will June
>10, 2017 be?  The few extra microseconds it takes for this bit to run is
>worth not having to code something that will take a string that could
>maybe possibly be construed as a date and return a nice "Weekday, Month
>##, Year"...  :)

Well, not to beat a dead horse, but Perl modules can do this just great.
And it is more than a few microseconds; on all my machines (including my
PPC 604e/180), it takes at least 3 seconds or so to compile and execute any
AppleScript.

The Time-Date modules on CPAN can do this for you, if you want.

  #!perl -wl
  use Date::Parse;
  use Date::Format;
  sub dateFromPerl { # :-)
    if (my $x = str2time($_[0])) {
      return time2str('%A, %B %e, %Y', $x);
    }
  }
  print dateFromPerl('01/01/98');
  print dateFromPerl('March 15, 1925');
  print dateFromPerl('June 10, 2017');

Returns:

  Thursday, January  1, 1998
  Sunday, March 15, 1925
  Saturday, June 10, 2017

--
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey=('B76E72AD',[1024,'0824 090B CE73 CA10  1FF7 7F13 8180 B6B6'])
#==               New Book:  MacPerl: Power and Ease               ==#
#==    Publishing Date: Early 1998. http://www.ptf.com/macperl/    ==#



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch