Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Alternative to POSIX::strptime

by astroboy (Chaplain)
on Jun 17, 2009 at 03:03 UTC ( [id://772213]=perlquestion: print w/replies, xml ) Need Help??

astroboy has asked for the wisdom of the Perl Monks concerning the following question:

Hi

This is a follow in from Fast way to validate dates

I'm using POSIX::strptime to provide a fast way to validate a date string given a POSIX date format. While it's working absolutely billiantly for me on Linux, it won't install on Mac OS X or Winodws (or, according to the CPAN test reports, on any flavour of UNIX)

Does someone know of an alternative? It needs to be quick because I'm processing lots of data, so anything based on DateTime won't cut it (oh, and it needs to understand POSIX format masks)

Replies are listed 'Best First'.
Re: Alternative to POSIX::strptime
by dsheroh (Monsignor) on Jun 17, 2009 at 09:34 UTC
    DateTime::Format::Strptime looks like it should be pretty cross-platform (162 pass/12 fail with passes on OSX and Win32) and, as a strptime implementation, I'd expect it to recognize your POSIX::strptime formats without modification.
Re: Alternative to POSIX::strptime
by Anonymous Monk on Jun 17, 2009 at 04:04 UTC
Re: Alternative to POSIX::strptime
by djerius (Beadle) on Jun 17, 2009 at 18:13 UTC
    Not quite an answer to your question, but still related...

    I've uploaded a patch (rt://46888) which allows the module to compile on Solaris; this may improve compilation success on other platforms. The tests will probably fail because the module seems to have been written based on the Linux behavior.

    I've discovered significant differences in how strptime behaves under OS X, Linux, and Solaris (see rt://46889 for comments on Solaris), not just in terms of whether the initial structure is initialized, but also in which fields are determined from the input string. There seems to be enough variation in how strptime is implemented that in my opinion it's not very useful in cross-platform code.

Re: Alternative to POSIX::strptime
by doug (Pilgrim) on Jun 17, 2009 at 15:20 UTC

    I've kinda given up on "validation" of dates. I usually use something like

    use Date::Manip; my $formatted_date = UnixDate $date, $PREFERRED_FORMAT;

    If Date::Manip::UnixDate() can figure out what was provided enough to produce a date in the format that I wish, then it was good enough. It isn't the fastest approach in the world, but it has served me well.

    - doug
Re: Alternative to POSIX::strptime
by davorg (Chancellor) on Jun 17, 2009 at 15:28 UTC

    What are you trying to install? There shouldn't be any need to install anything.

    POSIX.pm has been a part of the standard Perl installation since the earliest versions of Perl 5. If you have Perl 5 installed then you already have POSIX.pm and therefore POSIX::strptime.

    --

    See the Copyright notice on my home node.

    Perl training courses

      The 5.10.0 POSIX module doesn't look like it supplies strptime:
      % perl -v This is perl, v5.10.0 built for x86_64-linux-gnu-thread-multi [...] % perl -MPOSIX=strptime "strptime" is not exported by the POSIX module Can't continue after import errors at /usr/lib/perl/5.10/POSIX.pm line + 28 BEGIN failed--compilation aborted. % perl -MPOSIX -le 'print POSIX->VERSION' 1.13

        You're right. POSIX has never included strptime. It includes strftime. I apologise for being confused by the original question :-)

        --

        See the Copyright notice on my home node.

        Perl training courses

Re: Alternative to POSIX::strptime
by astroboy (Chaplain) on Jun 19, 2009 at 02:19 UTC
    Thanks to all who replied. Time::Piece seems to be working or me now...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://772213]
Approved by McDarren
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-19 20:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found