What does "||=" mean?

Can someone please give an explaination of the following line:

$starttime ||= $created

Exactly what does the "||=" expression mean, I haven't been able to find it in any documentation that I've got.
Who is Participating?
guadalupeConnect With a Mentor Commented:
Not to detract from the answers above which were good but the simple straight answer is that

$starttime ||= $created

means set $starttime equal to $created
unless $starttime is already defined/true remember that defined/true in perl is defined as other than 0 or the empty string ("") or any expression which evaluates to  such.  For a goo explanation of undefined/false read pages 20-21 in the Camel Book (Get a copy if you don't already own one.  It is the best book to learn Perl clear complete and concise.)
Kim RyanIT ConsultantCommented:
The OR assignmnent operator. It means take the result of
$starttime || $created (logical OR)
and assign the result to $starttime .

perldoc perlop

  C-style Logical Or

    Binary "||" performs a short-circuit logical OR operation. That
    is, if the left operand is true, the right operand is not even
    evaluated. Scalar or list context propagates down to the right
    operand if it is evaluated.

    The `||' and `&&' operators differ from C's in that, rather than
    returning 0 or 1, they return the last value evaluated. Thus, a
    reasonably portable way to find out the home directory (assuming
    it's not "0") might be:

        $home = $ENV{'HOME'} || $ENV{'LOGDIR'} ||
            (getpwuid($<))[7] || die "You're homeless!\n";

    In particular, this means that you shouldn't use this for
    selecting between two aggregates for assignment:

        @a = @b || @c;              # this is wrong
        @a = scalar(@b) || @c;      # really meant this
        @a = @b ? @b : @c;          # this works fine, though

    As more readable alternatives to `&&' and `||' when used for
    control flow, Perl provides `and' and `or' operators (see
    below). The short-circuit behavior is identical. The precedence
    of "and" and "or" is much lower, however, so that you can safely
    use them after a list operator without the need for parentheses:

        unlink "alpha", "beta", "gamma"
                or gripe(), next LINE;

    With the C-style operators that would have been written like

        unlink("alpha", "beta", "gamma")
                || (gripe(), next LINE);

    Use "or" for assignment is unlikely to do what you want; see

  Assignment Operators

    "=" is the ordinary assignment operator.

    Assignment operators work as in C. That is,

        $a += 2;

    is equivalent to

        $a = $a + 2;

    although without duplicating any side effects that dereferencing
    the lvalue might trigger, such as from tie(). Other assignment
    operators work similarly. The following are recognized:

        **=    +=    *=    &=    <<=    &&=
               -=    /=    |=    >>=    ||=
               .=    %=    ^=

    Note that while these are grouped by family, they all have the
    precedence of assignment.

    Unlike in C, the assignment operator produces a valid lvalue.
    Modifying an assignment is equivalent to doing the assignment
    and then modifying the variable that was assigned to. This is
    useful for modifying a copy of something, like this:

        ($tmp = $global) =~ tr [A-Z] [a-z];


        ($a += 2) *= 3;

    is equivalent to

        $a += 2;
        $a *= 3;
incAuthor Commented:
Thanks, just what I wanted for an answer.
All Courses

From novice to tech pro — start learning today.