Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: If unsuccessful action (updated)

by 1nickt (Canon)
on Apr 03, 2020 at 20:23 UTC ( [id://11115005]=note: print w/replies, xml ) Need Help??


in reply to If unsuccessful action

Hi,

" It seems that if it hits the timeout value in the if eval statement it does not proceed"

Well, it does nothing further in the outer if block shown ... impossible to see from what you posted what happens after it. The behaviour is apparently by design because essentially the block says:

if ( $outer_cond ) { if ( eval { func(); 1 } ) { do_something(); } }

I would start by adding an else block to the inner if block and printing some debugging from there if hit. It would be most helpful to print the error message if present; you could just use:

else { say "ERR $@"; }
... but I would replace the eval with Try::Tiny as it's so easy to do and so much better. Something like:
use Try::Tiny; if ( $outer_cond ) { my $ok = try { func(); 1; # not needed if func() returns something on success } catch { say "ERR $_"; 0; }; $ok ? do_something() : do_something_different(); }

Hope this helps!

updated: to show better program flow


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: If unsuccessful action
by fasteddye (Initiate) on Apr 03, 2020 at 21:18 UTC
    Thanks for the reply and suggestions. I have been trying to figure out a way to get some more debugging and I like the start by adding an ELSE block to the inner IF block. would I only need to add the listed ELSE say ERR suggestion or would there be some more additional syntax?

      Hi again,

      It's of course up to you how you debug. I showed the simplest pseudo action I could, as an example. But note that say is only available in Perl version >= 5.10 (and must be imported with use feature 'say'; or use 5.010;. It's the equivalent of print "$str\n";).

      Since you are starting a big ex post facto debugging project, you might like to begin to implement a logging system (using Log::Any) so that once you've fixed your issues you can run at a higher log level and the log statements you entered to debug will be ignored, but still there for future use (and could use different output adapters in production than in beta/testing, for example). That's what I would do.

      For a more quick-and-dirty tool while really debugging, where you aren't going to want to keep the statement, there's a newly updated module XXX by the mad genius Ingy döt Net I noticed recently that might be helpful.

      Hope this helps!


      The way forward always starts with a minimal test.

Log In?
Username:
Password:

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

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

    No recent polls found