pushtaev has asked for the wisdom of the Perl Monks concerning the following question:
Hello.
We are using Try::Tiny module in our project. I'm always using "try" instead of "eval" whenever I can, but eval can do some things, that "try" cannot: it's evaluation code from strings.
So, when I use eval() with string I should do something like this:
eval "require $module" or $self->error("...");
instead of nice and pretty
try "require $module" # It's not going to work catch { $self->error("..."); }
I can try something like this:
try { eval "require $module" or die $@; } catch { $self->error("..."); }
but it still looks ugly, because it's actually eval{eval""}.
Should I worry about this? Should I suggest improving Try::Tiny so it can "try" strings, not only blocks?
P. S. I believe the root of the problem is perl "eval" itself. It does two things for me (evaluate strings AND catch "exceptions") that are not really connected.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Try string, not block
by tobyink (Canon) on Sep 12, 2012 at 08:09 UTC | |
by pushtaev (Sexton) on Sep 12, 2012 at 08:16 UTC | |
|
Re: Try string, not block
by GrandFather (Saint) on Sep 12, 2012 at 08:15 UTC |