Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: time::piece Error parsing time at /usr/lib64/perl5/Time/Piece.pm line 469

by choroba (Cardinal)
on Mar 06, 2018 at 09:16 UTC ( [id://1210393]=note: print w/replies, xml ) Need Help??


in reply to Re: time::piece Error parsing time at /usr/lib64/perl5/Time/Piece.pm line 469
in thread time::piece Error parsing time at /usr/lib64/perl5/Time/Piece.pm line 469

eval{ $date = Time::Piece->strptime($1, '%m/%d/%Y') }; if ($@){

Please don't, see Bug in eval in pre-5.14. At least, use

if (eval { $date = Time::Piece->strptime($1, '%m/%d/%Y'); 1 }) { # ~~~~~
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^3: time::piece Error parsing time at /usr/lib64/perl5/Time/Piece.pm line 469
by darkwell (Initiate) on Mar 07, 2018 at 01:02 UTC

    Thanks poj and choroba. Eval solved it though I wish I understood why. I first tried:

    if (eval { $date = Time::Piece->strptime($1, '%m/%d/%Y'); 1 }) {

    as poj suggested but this generated the repetitive date 19700101. I tweaked it with:

    if (eval { $date = Time::Piece->strptime($&, '%m/%d/%Y'); 1 }) {

    and it generated what I had hoped.
    I read the docs on eval but I'm still unclear on what problem it resolved.
    Thanks again

      I read the docs on eval but I'm still unclear on what problem it resolved.

      Perhaps this simplified code will illustrate?

      #!/usr/bin/env perl use strict; use warnings; use Time::Piece; for my $input ('05/05/2000', 'notavaliddate') { my $date; if (eval { $date = Time::Piece->strptime($input, '%m/%d/%Y'); 1 }) + { print "Parsed '$input' into '$date' with eval\n"; } else { print "Attempted parsing of '$input' trapped by eval - life go +es on\n"; } if ($date = Time::Piece->strptime($input, '%m/%d/%Y')) { print "Parsed '$input' into '$date' without eval\n"; } else { # Next line never executed because program dies print "Attempted parsing of '$input' trapped without eval\n"; } } print "Run completed OK\n"; # This line will not be reached given bad +inputs
      this generated the repetitive date 19700101

      Did you have capture brackets around the date ?

      if($_=~/$first/) { $_=~/(\d+\/\d+\/\d+)/; # ^ ^
      poj

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2024-03-29 23:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found