PREVIOUS  TABLE OF CONTENTS 

The Perl Journal One-Liners

TPJ One-Liner #3

Using Perl from Emacs

To apply a Perl expression EXPR to a region:

C-u M-| perl -pe 'EXPR'

To apply EXPR to the entire buffer:

C-x h C-u M-| perl -pe 'EXPR'

Courtesy of Mark-Jason Dominus.

TPJ One-Liner #4

Preserving case in a substitution

To replace substring $x with an equal length substring $y, but preserving the case of $x:Z

$string =~ s/($x)/"\L$y"^"\L$1"^$1/ie;

Courtesy of Dean Inada.

TPJ One-Liner #5

Exploiting the F00F Pentium bug

require DynaLoader;
DynaLoader::dl_install_xsub("main::hangme",
        unpack("I", pack("P4", "\xF0\x0F\xC7\xC8")));
hangme();

Do NOT execute this. It will crash your computer.

Courtesy of Gisle Aas.

TPJ One-Liner #6

Primality

perl -le 'print "PRIME" if (1 x shift) !~ /^(11+)\1+$/' 19

Type this from your command line to test whether 19 (or any other integer of your choosing) is prime.

Courtesy of Abigail, abigail@fnx.com.


PREVIOUS  TABLE OF CONTENTS