<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body ><div>Wie war die Frida?</div><div>Wie viele wart Ihr? </div><div><br></div><div>Grüße,  </div><div>Jürgen</div><div><br></div><div><br></div><div><div style="font-size:75%;color:#575757">Von Samsung Mobile gesendet</div></div><br><br><br>-------- Ursprüngliche Nachricht --------<br>Von: Daniel Bruder <daniel@codeedition.de> <br>Datum: 16.04.2014  8:07  (GMT+01:00) <br>An: munich-pm@pm.org <br>Betreff: Re: [Munich-pm] Logic short circuit und Unterschied  || vs or <br> <br><br>Am 16.04.2014 07:23, schrieb Robert C. Helling:<br>> Hallo,<br>> <br>> hier noch eine Mail im Nachgang zum heutigen Treffen. In der Tat<br>> machen sowohl ‘||' als auch ‘or’ das gleiche logic short circuit (was<br>> die Ausführung angehen) und unterscheiden sich nur in ihrer<br>> Bindungsstaerke. Dazu ein kleiner Test<br>> <br>> #!/usr/bin/env perl<br>> <br>> sub a {<br>>   my $n = shift;<br>>   print "a says $n\n";<br>>   return $n;<br>> }<br>> <br>> sub b {<br>>   my $n = shift;<br>>   print "b says $n\n";<br>>   return $n<br>> }<br>> <br>> sub c {<br>>   my ($a, $b) = @_;<br>> <br>>   return $a || $b;<br>> }<br>> <br>> a(1) or b(2);<br>> a(3) || b(4);<br>> 2<3 || b(5);<br>> a(6) || 2<3;<br>> 2<3 or b(7);<br>> a(8) or 2<3;<br>> c(a(9), b(10));<br>> <br>> __OUTPUT__<br>> th-nb-tmpmbp01:or Robert.Helling$ ./test1.pl<br>> a says 1<br>> a says 3<br>> a says 6<br>> a says 8<br>> a says 9<br>> b says 10<br>> <br>> Es wird also immer von links nach rechts ausgewertet, auch wenn der<br>> Compiler schon sehen könnte, dass das zweite Argument den Ausdruck<br>> schon wahr macht (muss auch so sein, denn || hat als Wert den linken<br>> Wert, wenn dieser nicht false ist).<br>> <br>> So sieht das auch man perlop:<br>> <br>> C-style Logical Or<br>>        Binary "||" performs a short-circuit logical OR operation.<br>> That is, if the left operand is<br>>        true, the right operand is not even evaluated.  Scalar or list<br>> context propagates down to the<br>>        right operand if it is evaluated.<br>> <br>> […]<br>> As alternatives to "&&" and "||" when used for control flow, Perl<br>> provides the "and" and "or"<br>>        operators (see below).  The short-circuit behavior is<br>> identical.  The precedence of "and" and<br>>        "or" is much lower, however, so that you can safely use them<br>> after a list operator without the<br>>        need for parentheses<br>> <br>> Und wer meinen Vortrag beim 30c3 anschauen will, kann das hier tun:<br>> https://www.youtube.com/watch?v=3vM5u3VT_WE<br>> <br>> Viele Grüße<br>> Robert<br>> <br>> --<br>>  <br>>  <br>>  <br>>  <br>>  <br>>  <br>>  <br>>  <br>> .oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oO<br>> Robert C. Helling     Elite Master Course Theoretical and Mathematical <br>> Physics<br>>                       Scientific Coordinator<br>>                       Ludwig Maximilians Universitaet Muenchen, Dept. <br>> Physik<br>> print "Just another   Phone: +49 89 2180-4523  Theresienstr. 39, rm. <br>> B339<br>>     stupid .sig\n";   http://www.atdotde.de<br>> <br>> <br>> _______________________________________________<br>> Munich-pm mailing list http://munich.pm.org/<br>> Munich-pm@pm.org<br>> http://mail.pm.org/mailman/listinfo/munich-pm<br><br><br>In der Tat, ich lag falsch, und die perldoc bestätigt es:<br><br>   Binary "and" returns the logical conjunction of the<br>   two surrounding expressions.<br>   **It's equivalent to && except for the very low precedence.**<br>   This means that it short-circuits: the right expression is<br>   evaluated only if the left expression is true.<br><br>   <http://perldoc.perl.org/perlop.html#Logical-And><br><br>   (Hervorherbung von mir)<br><br>Ein kurzer Lookup in der "Spec" hätte uns einiges an Zeit ersparen <br>können :)<br>_______________________________________________<br>Munich-pm mailing list http://munich.pm.org/<br>Munich-pm@pm.org<br>http://mail.pm.org/mailman/listinfo/munich-pm<br></body>