develooper Front page | perl.perl5.porters | Postings from September 2011

Re: RFC: Second attempt at POSIX::strptime() in core

Thread Previous | Thread Next
From:
Paul LeoNerd Evans
Date:
September 8, 2011 08:52
Subject:
Re: RFC: Second attempt at POSIX::strptime() in core
Message ID:
20110908155159.GG18491@cel.leo
On Fri, Sep 02, 2011 at 11:38:29AM +0100, Nicholas Clark wrote:
> Am I right in thinking that the information strptime() wants to return is
> 
> a) the values of what it parsed
> b) what things it could parse (zero or more from seconds, minutes, hours, etc)
> c) where in the string the parse failed
> 
> ?
> 
> The problems being that strptime() in Time::Piece only tells you (a),
> and has no way of telling you (b) or (c)?

Yes; entirely.

My proposed alternatives of

  my @t = localtime()
  strptime $fmt, $str, \@t

or

  my @t = strptime $fmt, $str, localtime()

would signal b) by virtue of not altering (in the ARRAYref case), or
returning passthrough (in the function case) the fields that were
unaltered.

The signal for c) is a little more complex - I pondered abusing the
pos() marker on it, a.la. 

  http://search.cpan.org/~pevans/Term-TermKey-0.10/lib/Term/TermKey.pm#$key_=_$tk->parse_key_at_pos(_$str,_$format_)

though I admit I don't yet have a complete specification on this regard.

-- 
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk
ICQ# 4135350       |  Registered Linux# 179460
http://www.leonerd.org.uk/

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About