Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Hi,
    In your question you wrote:
    if the return value from that subroutine is true, this subroutine should return that value, otherwise continue.
    I don't see that happening with just this line:
    eval { return thatroutine() || die };
    The "return" will return the value of "thatroutine()" outside the "eval", but it won't cause the inclosing subroutine to return, if I read the docs correctly. What am I missing?

    Anyway, I usually prefer a simple, readable solution, one that doesn't depend on the short-circuit behaviour of "&&" and relatives (not everyone groks such code), even if it is a little more verbose. How about:
    # I also dislike single letter variable names ;-)
    if (my $significant_name = thatroutine()) {
       return $significant_name
    • (not everyone groks such code)

      Sorry, but that's a very poor reason to avoid the short circuit behaviour of boolean ops. Programmers worth their salt must know about it, it such a basic tool, so helpful tool for improving legibility, and so widespread among languages. Without flinching I will go so far as to suggest that those who really cannot figure it out even after explanations, possibly repeated, shouldn't be touching code in the first place.