Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Perl Idioms Explained - && and || "Short Circuit" operators

by Abigail-II (Bishop)
on Oct 22, 2003 at 21:31 UTC ( #301380=note: print w/replies, xml ) Need Help??

in reply to Perl Idioms Explained - && and || "Short Circuit" operators

--------------------------------------------------------- $this && $that | If $this is true, and $that is true | return the value of the last | expression evaluated ($that). -----------------+--------------------------------------- $this || $that | If $this evaluates true, stop | evaluating, we're done. Otherwise | evaluate $that for truthfulness. | If $that evaluates true, return | the value of $that. ---------------------------------------------------------

That doesn't explain what is returned if $that is false. May I suggest the following (which is shorter, symmetric, and explains the return value on failure).

--------------------------------------------------------- $this && $that | If $this is true, return $that, | else return $this. -----------------+--------------------------------------- $this || $that | If $this is true, return $this, | else return $that. ---------------------------------------------------------


Replies are listed 'Best First'.
Re: Re: Perl Idioms Explained - && and || "Short Circuit" operators
by davido (Archbishop) on Oct 22, 2003 at 21:34 UTC
    Thanks Abigail. The node has been updated per your suggestion. Good catch.


    "If I had my life to do over again, I'd be a plumber." -- Albert Einstein

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://301380]
[Corion]: erix: Yeah, I just found that it has no documentation at all on how to circumvent/ eliminate "1+n SELECTs" by building a local hash... I guess I have to make ->has_many do the hash lookup instead of doing the SQL query. But as the problem ...
[Corion]: ... has only manifested itself so far through the puzzled questions of other bystanders, I won't go deeper at this time. But the DBIx::Class documentation could well do with a document on how to make "it" (that is, ORMs in general) faster ;)
[Corion]: I find that DBIx::Class, like most ORMs makes things easy until they become performance critical and then makes it horribly hard to change things because the design is highly inflexible if you don't already know about the problems of 1+n :-/
[choroba]: that's why I don't like similar libraries. They pretend you don't have to learn SQL, but in the end, you have to learn how SQL plus to overcome their own limitations
[Corion]: "Just write the proper SQL beforehand" is of course the appropriate solution, but if you did that, you wouldn't/couldn't use DBIx::Class either. At least not in an obvious (to me) way.
choroba scratches a "how"
[Corion]: choroba: Exactly... But maybe that's just because I'm old and grumpy ;)
[Corion]: But maybe that could also be a nice talk, how to restructure your DBIx::Class-based app to remove 1+n-style query patterns
[Corion]: In theory, that should be easy because you should have the "where" clause from part 1 of the patterns and then do the corresponding single select using that where clause to select all rows in one go for the n other parts.
[Corion]: But in practice I don't see any obvious places documented in DBIx::Class where one would do that and then just feed hash lookups instead of DB lookups for ->has_many results

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2017-09-25 11:11 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (279 votes). Check out past polls.