Time::Piece capturing parsing problems



Hi everyone,

I think my question relates to STDOUT rather than Time::Piece but I'm not
sure.

I am trying to use Time::Piece to process and convert a string which may be
a bit dodgy. What I can't understand is how to capture the problem. The
following code only captures the problem with the second test in the
$EVAL_ERROR ($@). The problem with the first one ("garbage at end of string
in strptime: ...") just goes to the screen - but I need to be able to handle
it.

This is a snippet of code to show what I mean:

# # # # # # #
#!/usr/bin/perl
use strict;
use warnings;

use Time::Piece;

my @tests = ( '28 FEB 2008 stuff at the end to see what Time::Piece does',
'blah 28 FEB 2008' );
my $format = '%d %h %Y';

foreach my $i ( 0..$#tests ) {
print "\nTEST $i\n";
eval {
my $date_object= Time::Piece->strptime($tests[$i], $format);
print $date_object->dmy("/") . "\n";
};
if ($@) {
print "eval error: $@";
}
}
# # # # # # #

The output from running this is:

$ perl test.pl

TEST 0
garbage at end of string in strptime: stuff at the end to see what
Time::Piece does at C:/Perl/site/lib/Time/Piece.pm line 470.
28/02/2008

TEST 1
eval error: Error parsing time at C:/Perl/site/lib/Time/Piece.pm line 470.
$



--
Myf White

Work like you don't need the money. Love like you've never been hurt. Dance
like nobody's watching.
~ Satchel Paige


Relevant Pages

  • Re: Length of longest contiguous digits exercise
    ... this contiguous block of 1s is remembered ... string must not appear at any other point in the string. ... this is undefined when there is no capture ... (which happens when there are no digits in the ...
    (comp.lang.javascript)
  • Re: Regex Capture problem
    ... "learned" my regex using a freeware utility that had slightly different ... was trying to capture instead of. ... I have used Regex utilities before, so I understand the concepts of text ... Function RESub(str As String, SrchFor As String, ReplWith As String) As String ...
    (microsoft.public.excel.programming)
  • Re: SQL - Capture Specific Text and Copy to New Column/row
    ... The script is: ... Please advise of how I may capture only the date/time data. ... wildcard characters as characters in the string. ... by the Option Compare setting of the module. ...
    (microsoft.public.access.modulesdaovba)
  • Re: Regular Expression Hangs
    ... You wouldn't need a regular expression to ... a single fixed string. ... Those patterns are defined by rules that are expressed in the ... will capture the following: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: how to get all repeated group with regular expression
    ... string, such as string '123456', i tried re.findall*, ... nature to all regx engine or only to Python? ... issues that I can perfectly understand why Python works the way it does, ... Yes, you are right, but this way findallcapture only the 'top' group. ...
    (comp.lang.python)