Courtesy of Mark-Jason Dominus.
To replace substring $x with an equal length substring $y, but preserving the case
of $x:Z
Courtesy of Dean Inada
Courtesy of Gisle Aas
#6 Primality
Courtesy of Abigail, [email protected]
#7 An Absurd Way To Convert From Decimal To Binary
Courtesy of Nathan Torkington
#8 How To Patch Your Netscape Binary To Enable Strong Encryption
Courtesy of Ian Goldberg
#9 How To Use The Perl Debugger as a Command-Line Interpreter
#10 Using PDL to Generate Fractals
Courtesy of Tuomas J.Lukka
#1
Adding a long list of numbers on the command line:
perl -e 'print eval join("+", @ARGV)' 6 10 20 11
9 16 17 28 100 33333 14 -7
#2
A cheap alarm clock:
perl -e 'sleep(120); while (1) { print "\a" }'
#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'
appeared in Issue 8
#4 Preserving case in a substitution
$string =~ s/($x)/"\L$y"^"\L$1"^$1/ie;
appeared in Issue 8
#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.
appeared in Issue 8
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.
appeared in Issue 8
#!/usr/bin/perl
($decimal, $binary) = (shift, '');
$SIG(USR1) = sub { $binary .= "0"};
$SIG(USR2) = sub { $binary .= "1"};
do { kill $decimal & 1 ? 'USR2' : 'USR1' , $$;
$decimal >>= 1;
} while ($decimal);
print scalar reverse $binary;
appeared in Issue 9
#!/usr/bin/perl -0777pi
s/TS:.*?\0/$_=$&;y,a-z, ,;s, $,true,gm;s, 512,2048,;$_/es
appeared in Issue 9
perl -de 0
use PDL; use PDL::IO::Pic;$a=zeroes 300,300;
$r=$a->xlinvals(-1.5,0.5);$i=$a->ylinvals(-1,1);
$t=$r;$u=$i;for(1..30){$q=$r**2-$i**2+$t;$h=2*$r*$i+
$u;$d=$r**2+$i**2;$a=lclip($a,$_*($d>2.0)*($a==0));($r,
$i)=map{$_->clip(-5,5)}($q,$h);}$a->wpic("mandel.gif");
appeared in Issue 9