Re: How to check if a DateTime is invalid (again - but this time without using eval)?

[email protected] (Rick Measham) Mon, 3 Jul 2017 21:09:26 +1000
Newsgroups perl.datetime
Message-ID <[email protected]>
I'm not sure what you mean by 'local DIE handlers'. Are you talking 
about defining a local $SIG{__DIE__} ?

I've been out of perl for a couple of years, but surely you should just 
use eval{} ?


$dt = eval { $parser->parse( $input );};

if( $@ ){

    echo "Unable to parse your date ($input)\n";

    exit;

}

echo "Your date is $dt\n";


- Rick



On 3/07/2017 17:49, Binarus wrote:
> On 02.07.2017 22:02, Eric Brine wrote:
>> `eval BLOCK` is very different `eval EXPR`.
>>
>> The latter involves the need to generate Perl code, and ask the related
>> risks. That's not the case for the former, which is the right tool for
>> the job here.
>>
> Thank you very much for your answer. I have decided to solve my problem
> by using a block eval, probably with a local DIE handler added in the
> block (but still thinking about whether this is necessary - I won't use
> other DIE handlers and don't need to "catch errors" at any other places).
>
> Regards,
>
> Binarus

-- 
Message  protected for iSite by MailGuard: e-mail anti-virus, anti-spam and content filtering.http://www.mailguard.com.au