Re: Time::Piece capturing parsing problems
- From: noreply@xxxxxxxxx (Gunnar Hjalmarsson)
- Date: Thu, 28 Feb 2008 18:01:02 +0100
Myf White wrote:
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.
I for one think it's a result of how Time::Piece works...
One option might be to use 'good old' Date::Parse instead:
$ cat test.pl
use Date::Parse;
my @tests = ('28 FEB 2008', 'garbage 28 FEB 2008',
'28 FEB 2008 garbage');
foreach my $i ( 0..$#tests ) {
print "TEST $i\n";
if ( my ($d, $m, $y) = ( strptime $tests[$i] )[3..5] ) {
printf "%02d/%02d/%d\n", $d, $m+1, $y+1900;
} else {
warn "Parsing of '$tests[$i]' failed";
}
}
$ perl test.pl
TEST 0
28/02/2008
TEST 1
Parsing of 'garbage 28 FEB 2008' failed at test.pl line 8.
TEST 2
Parsing of '28 FEB 2008 garbage' failed at test.pl line 8.
$
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
.
- References:
- Time::Piece capturing parsing problems
- From: Myf White
- Time::Piece capturing parsing problems
- Prev by Date: Re: Data file from one format to another.
- Next by Date: Re: Time::Piece capturing parsing problems
- Previous by thread: Time::Piece capturing parsing problems
- Next by thread: Re: Time::Piece capturing parsing problems
- Index(es):
Relevant Pages
|