PREV Examples NEXT

Mutagens

  • Make regular expressions work backwards:
    use overload;
    
    BEGIN {
        overload::constant qr => sub {
            return reverse shift();
        };
    }
    
    print "It worked!\n" if "foo" =~ /oof^/;

  • Make subroutine calling case-insensitive:
    sub AUTOLOAD {
        no strict 'refs';
        goto &{lc $AUTOLOAD};
    }
    
    sub foo {
        print "It worked!\n";
    }
    
    FoO();

  • Initialise all global variables to zero:
    CHECK {
        while (my($n,$v) = each %::) {
            $$v = 0 if !defined $$v;
        }
    }
    
    print "It worked!\n" if defined($any_variable)
                         && $any_variable == 0;

  • Everything should be printed backwards:
    sub TIEHANDLE {my $x; bless \$x}
    sub PRINT {
        shift;
        print REALOUT map scalar reverse, reverse @_;
    }
    open(REALOUT, ">&STDOUT");
    tie *STDOUT, "main";
    print "\n!dekrow", " tI"

Extensions

  • I'm an lvalue subroutine. Was I called in lvalue or rvalue context?
    use Inline C => <<NOMO;
    
    U8 wantlvalue ()
    {
        return cxstack[cxstack_ix].blk_sub.lval;
    }
    
    NOMO
    
    sub foo :lvalue {
        print (wantlvalue() ? "lvaluably\n" : "rvaluably\n");
        my $foo
    }
    
    foo();
    foo() = 23;
  • >>