Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Or Operator

by fruiture (Curate)
on Jul 30, 2004 at 23:04 UTC ( #378829=note: print w/ replies, xml ) Need Help??


in reply to Or Operator

The magic term is "operator precedence", it determines the order of execution or your atomic expressions.

A = B or C; # as "=" has higher precedence than "or" it binds it's # arguments "tighter", so this is equivalent to (A = B) or C; # so your expression is a disjunction # which executes the left operand (A = B) # being an assignment, which returns B in the end # and if that's false, the disjunction (or) # returns C, which is irrelevant, because that's in void # context # but you want A = (B or C) # because that's an assignment, an assignment # evaluates the right operand first (B or C) # which itself is a disjunction again and works as described # above, returning B if true, otherwise C # and that is then assigned to A, which must be an lvalue # that means in Perl my $page = ( $cgi->param("page") or "login" ); # or by using the high-precedence-OR "||" my $page = $cgi->param("page") || "login"; # because "||" has higher precedence than "="

see perlop

--
http://fruiture.de


Comment on Re: Or Operator
Download Code
Replies are listed 'Best First'.
Re^2: Or Operator
by rjahrman (Scribe) on Jul 30, 2004 at 23:47 UTC
    I have another similar line:
    $ftp = Net::FTP->new("ftp.$dom", Debug => 0) or $loginerror = "Error message.";

    Should this work like I think it does?

      If you think it will set $ftp to the result of the new method call, and if that was false set $longin error, it will.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (16)
As of 2015-07-07 22:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls