Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

by demerphq (Chancellor)
on Oct 22, 2003 at 22:10 UTC ( #301397=note: print w/replies, xml ) Need Help??


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

C-style?

You split "C-style" and "short cicuit" into two sections. The whole point of refering to them as "C-Style" is because they are "short circuit". I believe the reason was that C is the most commonly known old school language that defines its logical operators to "short circuit". Turbo Pascal's logical operators were short circuit, but I dont know if this is part of the Pascal language definition, or just one of many Borland extensions. OTOH, Basic generally does not have short circuit operators (and thus presumably Fortran does not have them either). However I'd guess that most modern languages have operators which short circuit considering the convenience they offer. Without them you have to write this

if (defined $array->[1] and $array->[1] eq 'foo') { ... }

as a nested if, like this

if (defined $array->[1]) { if ($array->[1] eq 'foo') { ... } }

which is a source of perpetual frustration to me when I have to hack on VB code. (A chore that luckily I do very rarely these days.)

Anyway, good meditation.


---
demerphq

    First they ignore you, then they laugh at you, then they fight you, then you win.
    -- Gandhi


Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://301397]
help
Chatterbox?
[zentara]: Jesus would never bite Ganeesh ! Jesus didn't fight or eat meat
[choroba]: Didn't fight?
[erix]: ganesh in musht?
[LanX]: as a monotheist he would fight other problems
LanX succesfully trolled the CB into religion and leaves now! :)
[erix]: looking for his navel
[choroba]: Cleansing of the Temple
[zentara]: Unicorns are not conceived, they are created. Unicorns don't want another life. :-)
[erix]: you go check your data LanX :P
[Your Mother]: marto++ (me as well)

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (12)
As of 2017-03-30 16:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (361 votes). Check out past polls.