develooper Front page | perl.datetime | Postings from July 2017

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

Thread Previous | Thread Next
From:
Rick Measham
Date:
July 3, 2017 11:10
Subject:
Re: How to check if a DateTime is invalid (again - but this timewithout using eval)?
Message ID:
77a101b3-3004-151e-a408-23c0b0951649@measham.id.au
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


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