The concise nature of [[Perl]] syntax permits miniscule yet powerful programs called "one liners" because they're easy to run from a command line. Line breaks have been added here. ---- '''A simple web server that works with static and dynamic pages''' perl -MIO::All -e 'io(":8080")->fork->accept->( sub { $_[0] < io(-x $1 ? "./$1 |" : $1) if /^GET \/(.*) / })' From [http://search.cpan.org/~ingy/IO-All/lib/IO/All.pod#DESCRIPTION http://search.cpan.org/~ingy/IO-All] ---- '''Portscanner''' perl -MIO::Socket -wle"map { IO::Socket::INET->new(qq($ARGV[0]:$_)) and print } 1..$ARGV[1]||10000" localhost 1000 From [http://web.archive.org/web/20021004112932/http://www.chrisangell.com/oneliners.html http://www.chrisangell.com/oneliners.html] ---- '''Mandelbrot''' perl -MPDL -MPDL::IO::Pic -e '$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");' From [http://web.archive.org/web/20031025003129/http://www.tpj.com/documents/s=7228/tpjoneliners/one-liners01.html http://www.tpj.com/documents/s=7228/tpjoneliners/one-liners01.html] ---- '''Rock, Scissors, Paper''' perl -e "$c=(($r,$s,$p)=qw|rock scissors paper|)[(int rand 3)]; $|=0; until($y=~/^($r|$s|$p)$/){print \"$r, $s or $p? \";$y=<>;chop $y}; %r=($s,{$p,1,$r,0},$p,{$r,1,$s,0},$r,{$s,1,$p,0}); print \"You: $y\nCom: $c\nYou \". ((exists $r{$y}{$c}?($r{$y}{$c}?'Win': 'Lose'):'Draw').\"\n\")" '''Bone::Easy <-> Chatbot::Eliza''' perl -MChatbot::Eliza -MBone::Easy -e "$a=Chatbot::Eliza->new(); for(0..$ARGV[0]){$b=pickup(); $c=$a->transform($b); print \"Bone: $b\nLiz: $c\n\"}print 'Liz: '.$a->final()->[0].\"\n\"" 10 From [http://web.archive.org/web/20020515231840/http://rollmop.org/oneliners/perl.html http://www.rollmop.org/oneliners/perl.html] ---- == CGI == '''World's Shortest Wiki'''
#!/usr/bin/perl
use CGI':all';path_info=~/\w+/;$_=`grep -l $& *`.h1($&).escapeHTML$t=param(t)
||`dd<$&`;open F,">$&";print F$t;s/htt\S+|([A-Z]\w+){2,}/a{href,$&},$&/eg;
print header,pre"$_