http://qs321.pair.com?node_id=1194690


in reply to How to format dates prior to 1970?

Your code works for me on both Perl 5.22 on MacOS X and on Perl 5.16.3 on Ubuntu Linux:

$ perl 1194689.pl 1969-05-10 1969-05-10


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: How to format dates prior to 1970?
by Hanfresco (Novice) on Jul 10, 2017 at 13:19 UTC
    Thanks for the response. But that is bizarre. I get a Windows pop-up that says
    Perl interpreter has stopped working A problem caused the program to stop working correctly. Windows will c +lose the program and notify you if a solution is available.
    What system are you running the code on? If I click "Debug" and open this with Microsoft Visual Studio, I get
    Unhandled exception at 0x000000006F4C230B (Piece.xs.dll) in perl.exe: +0xC0000005: Access violation reading location 0x0000000000000000. If there is a handler for this exception, the program may be safely co +ntinued.

      Just FWIW: problem occurs with with AS 5.24 on Win 7-64:

      C:\>perl -v * This is perl 5, version 24, subversion 0 (v5.24.0) built for MSWin32-x86-multi-thread-64int on Win 7 pro, 64bit
      #!/usr/bin/perl use v5.10; # (OP's code, verbatim) use strict; use warnings; use Data::Dumper; use DateTime::Format::Strptime; use Time::Piece; $Data::Dumper::Sortkeys = 1; my $date = '05/10/1969'; my $ymd = '%Y-%m-%d'; my $mdy = '%m/%d/%Y'; my $t = Time::Piece->strptime($date,$mdy); say $t->ymd; # Prints as normal say $t->strftime($ymd); # Segmentation fault

      Execution:

      C:\>F:\_Perl_\PMonks\1194689.pl 1969-05-10 C:\> And, the same popup as cited above with the following content: Problem signature: Problem Event Name: APPCRASH Application Name: perl.exe Application Version: 5.24.0.2400 Application Timestamp: 578689b9 Fault Module Name: Piece.dll Fault Module Version: 0.0.0.0 Fault Module Timestamp: 57868a01 Exception Code: c0000005 Exception Offset: 00002398 OS Version: 6.1.7601.2.1.0.256.48 Locale ID: 1033 Additional Information 1: 0a9e Additional Information 2: 0a9e372d3b4ad19135b953a78882e789 Additional Information 3: 0a9e Additional Information 4: 0a9e372d3b4ad19135b953a78882e789
        What version of Time::Piece are you using?

      Well, since the exception is apparently caused by Time::Piece (even though it's a core module), try using something else:

      use strict; use warnings; use feature 'say'; use DateTime::Format::Strptime; my $parser = DateTime::Format::Strptime->new(pattern => '%m/%d/%Y', on +_error => 'croak'); my $date = '05/10/1969'; my $dt = $parser->parse_datetime( $date ); say $dt->ymd;
      What does that do on your Windows system?


      The way forward always starts with a minimal test.
        #!/usr/bin/perl use v5.10; use strict; use warnings; use Data::Dumper; use DateTime::Format::Strptime; $Data::Dumper::Sortkeys = 1; my $parser = DateTime::Format::Strptime->new(pattern => '%m/%d/%Y', on +_error => 'croak'); my $date = '05/10/1969'; my $dt = $parser->parse_datetime($date); say $dt->ymd; say $dt->strftime('%Y-%m-%d');
        Interesting! This seems to work even with strftime; no seg faults!