in reply to What does the short circuit || mean ?

On the first line, || evaluates the left side first. If it's true, it gets assigned to $ct, otherwise, $ct becomes text/plain.

On line 2, you can add parentheses as follows:

(($ct eq 'text/plain') || ($ct eq 'text/html')) or next;

which makes it equivalent to

next if $ct ne 'text/plain' and $ct ne 'text/html';

The "short circuiting" is most noticable in the or operator: next is evaluated only if the previous condition is false.

لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: What does the short circuit || mean ?
by peterr (Scribe) on Mar 10, 2015 at 01:06 UTC
    Thanks choroba for explaining that.

    It's like saying if $part->contentType is undefined, $ct will default to a value of "text/plain"

      ... if $part->contentType is undefined ...

      This is a little tricky, but to be precise, you're saying "if $part->contentType is false", then do something. In Perl, falsity is represented by any of: undef (the undefined value), "" (the empty string), 0 (numeric zero), or '0' (a string consisting of a single 0 character). Use the  // operator to test specifically for defined-ness.

      Update: See also True and False (aka Booleans).


      Give a man a fish:  <%-(-(-(-<

        Thanks AnomalousMonk, that is a great guide for understanding true or false.