This presentation is an HTML5 website

Its format is a direct ripoff of this HTML 5 presentation.

Press key to advance.

Zoom in/out: Ctrl or Command + +/-

Having issues seeing the presentation? Read the disclaimer

perlopquick

A Perl 5 operator quick reference

perlop is hard for newbies to use






What does $wait ||= 5 do?

  • find ||= in perlop
  • realize you have to read about += first
  • understand how += works
  • apply that understanding to how ||= works
  • go lookup ||
perlop doesn't tell you why






We still don't know that

  • it is a common idiom for setting defaults
  • it is dangerous (0 and empty strings are replaced)
  • you should probably be using //= instead
perlop cannot be parsed



It would be nice to be able to say

perldoc -O "||="

Like we currently do for

perldoc -f splice
perldoc -v "$/"

perlopquick is already used by App::Padre to provide context sensitive help for operators

I am a masochist






Initial idea for the docs:

=head2 C<X ||= Y>

    This is equivalent to C<X = X || Y>, see C<||> and C<=> for more
    information.
I am a masochist
=head2 X ||= Y

    =head3 Class

    This belongs to L<perlop/Assignment Operators>.

    =head3 Description

    This is the logical or assignment operator.  It is equivalent to

        X = X || Y

    That is it logically ors together X and Y and then assigns the result to X.
    This means that X must be a valid lvalue (i.e. it must be something that can
    be assigned to).  It was often used in the past to assign a value if the
    variable did not already have a value:

        my $x;

        #intervening code that might set $x or might leave it undefined

        $x ||= 10; #make sure $x gets set to a default value

    This has a problem though: if C<$x> is C<0> or C<""> then it will get
    overwritten with C<10>.  The defined-or assignment operator (L</X //= Y>)
    does not have this problem and should, generally, be used for this purpose
    instead.  Of course, if you desire any false value be overwritten, then this
    is the right operator to use.

    =head3 Example

        my $x = 2;
        my $y = 8;
        my $z;

        $x ||= $y; #$x is now 2 || 8 or 2
        $y ||= $x; #$y is now 8 || 2 or 8

        my $z ||= $x + $y; #$z is now undef || (2 + 8) or 10

    =head3 See also

    L</X = Y>, L</X E<verbar>E<verbar> Y>, and L</X E<sol>E<sol>= Y>
I am a masochist






Every operator gets four sections:

  1. The part of perlop it is in
  2. A description of what it does
  3. A block of example code
  4. A list of other operators or topics of interest
What can you do?



I need help from people willing to:

  • proofread it
  • edit it
  • test its examples
  • use it as a reference

So, run out and get it at http://github.com/cowens/perlopquick