TPJ One-Liner #6Primality Adding a long list of numbers on the command line:
perl -le 'print "PRIME" if (1 x shift) !~ /^(11+)\1+$/' 19Type this from your command line to test whether 19 (or any other integer of your choosing) is prime. Courtesy of Abigail, abigail@fnx.com
|
TPJ One-Liner #5Exploiting 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 #4Preserving 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 #3Using 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.
|