Got some code which would take a Perl grand master to understand without running it?
Post it in this section so we can stare at it in awe.
Word of warning, though:
Don't be too cocky with your post — almost inevitably someone will post a reply that does the exact same thing in even fewer characters!
New Less than Readable Code
|
The Backslash Challenge
4 direct replies — Read more / Contribute
|
by choroba
on Mar 24, 2021 at 16:12
|
|
To return the character that's used as the delimiter in a quote-like operator, you can use a backslash.
'/' eq q/\// or die "Failed";
Your task is to return a backslash using a backslash as the delimiter. Use qq\\ for level easy, use q\\ for level guru.
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
|
The IP address I'd like to own -- oneliner
1 direct reply — Read more / Contribute
|
by Discipulus
on Mar 16, 2021 at 03:13
|
|
|
Emoji can be hard to see on the command line
1 direct reply — Read more / Contribute
|
by kcott
on Feb 06, 2021 at 14:16
|
|
++eyepopslikeamosquito's post (a reply in an unrelated SoPW thread) inspired me to look at
Acme::EyeDrops.
After playing around with that module for a bit, I realised that some of the obfucation code images
looked a bit like blown-up versions of emoji.
It then occurred to me that not only could I get large, very easy to see, representations of emoji,
but I could also use those images to get back the original Unicode® emoji character.
Here's a couple of examples.
Firstly, a very straightforward one that only required one shape.
$ perl -C -e 'print "\x{1f56f}\n"'
🕯
$ cat candle.txt
(
( (
( (
( ( ( (
(
( ( ( ( ( (
''
) ) ))) ) ) ) )
) )))))
) =~("\(". (
( '?')).'{' . (
( '`')|'%')
.('['^ ( '-')
) . ( '`'|'!')
. ('`'|"\,").
'"'.('['^"\.").(
'['^'(').('`'|('%')).(
'{'^'[').('`'|'/').(('[')^
'+').('`'|'%').('`'|'.').(
'{'^'[').('['^'*').("\["^
',').'\\'.'{'.':'.(('[')^
'(').('['^'/').('`'|'$').(
'{'^'[').':'.('`'|'%').('`'
|'.').('`'|'#').('`'|"\/").(
'`'|'$').('`'|')').(('`')|
'.').('`'|"'").'('.(('{')^
'.').('{'^'/').('`'^'&'
).'-'.(':'&'=').')'.''.
'\\'.'}'.';'.('!'^'+').
('['^'+').('['^(')')).(
'`'|')').('`'|'.').('['
^'/').('{'^'[').('\\').
'"'.'\\'.'\\'.('['^'#')
.'\\'.'{'.('^'^('`'|'/'
)).('`'|'&').('^'^('`'|
( '+'))).('^'^('`'|'(')).
('`'|'&') .'\\'.'}'.'\\'.('\\').( ( (
'`'))|('.')). '\\'.'"'.';'.('!'^'+'). ( '"')."\}".
')');$:='.'^"\~"; $~='@'|'(';$^=')'^"\["; $/='`'|'.';$,='('
^+ '}';$\='`'|'!';$:=')'^'}';$~='*'|'`' ;$^='+'^'_';$/="\&"|
(( '@'));$,='['&'~';$\=','^'|';$:='.'^'~';$~='@'|'(';
($^) =')'^'[';$/='`'|"\."; $, = ( (
( '(')))^"\}";
$\='`'|'!';$:=
')'^'}';$~='*'|'`'
;$^='+'^'_';$/='&'
|(( '@' ));
$ perl -Mre=eval candle.txt
🕯
And a tad more complicated one that required two shapes.
$ perl -C -e 'print "\x{1f459}\n"'
👙
$ cat bikini.txt
''=~('('. '?'.'{'.(
(( (( (( ((
(( (( (( ((
(( (( ( ((
(( (( (( ((
(( (( (( ((
(( (( (( (
(( (( (( ((
(( (( ( (
(( ( (( ((
( (( (( ((
( (( (( ((
( ( (( ((
( (( (( ((
(( ( (( (
(( (( ( ((
(( (( (( '`'
)))) ) )) ))))
))))) )) )) ))))))
))))))) )) )) )))))))
))))))))) )) )) )))))))))
))))))))))))) )))))))))))))
))))))))))))) ))))))))|'%').
('['^'-').('`'| '!').('`'|"\,").
'"'.('['^'.').('['^ '(').('`'|('%')).(
'{'^'[').('`'|"\/").( '['^'+').('`'|('%')).(
'`'|'.').('{'^'[').("\["^ '*').('['^',').'\\'.('{').
':'.('['^'(').('['^('/')).( '`'|'$').('{'^'[').':'.("\`"|
'%').('`'|'.').('`'|'#').('`'|'/').('`'|'$').('`'|')').('`'
|'.').('`'|"'").'('.('{'^'.').('{'^'/').('`'^'&').('-').(
':'&'=').')'.'\\'.'}'.';'.('!'^'+').('['^'+').('['^')')
.('`'|')').('`'|'.').( '['^'/').('{'^('[')).
'\\'.'"'.('\\'). '\\'.('['^'#').
'\\'.'{'. ('^'^('`'
|'/')).('`'|'&').('^'^('`'|'*')).('^'^('`'|'+')).((';')&
'=').'\\'.'}'.'\\'.'\\'.('`'|'.').'\\'.'"'.';'.('!'^'+')
.'"'.'}'.')');$:='.'^'~';$~='@'|'(';$^=')'^'[';$/=('`')|
'.';$,='('^'}';$\='`'|'!';$:=')'^'}';$~='*'|'`';$^="\+"^
'_';$/='&'|'@';$,='['&'~';$\=','^'|';$:='.'^'~';$~="\@"|
'(';$^=')'^'[';$/='`'|'.';$,='('^'}';$\='`'|'!';$:="\)"^
'}';$~='*'|'`';$^='+'^'_';$/='&'|'@';$,='['&'~';$\
=','^'|';$:='.'^'~';$~='@'|'(';$^=')'^'[';$/
='`'|'.';$,='('^'}';$\='`'|'!';$:=')'^
'}';$~='*'|'`';$^='+'^'_';$/="\&"|
'@';$,='['&'~';$\=','^"\|";$:=
'.'^'~';$~='@'|'(';$^=')'^
'[';$/='`'|'.';$,=('(')^
'}';$\='`'|'!';$:=')'^
'}';$~='*'|('`');$^=
'+'^'_';$/='&'|'@'
;$,='['&"\~";$\=
','^'|';$:='.'
^'~';$~=('@')|
'(';$^="\)"^
'[';$/="\`";
$ perl -Mre=eval bikini.txt
👙
In case you were wondering why one is coloured and the other isn't:
CANDLE (U+1F56F) does not have the Emoji_Presentation property, so it defaults to text style;
BIKINI (U+1F459) does have that property, so it defaults to emoji style.
If this interests you, see "Text vs Emoji, v13.1" for specific information,
and "Unicode® Emoji Charts v13.1" for links to more general discussions.
Finally, in case it wasn't obvious, this was intended as a bit of tongue-in-cheek fun.
My eyesight is not so poor that I need foot-high images to tell one emoji from another.
👁️ 😕 👓 😃
|
Making a point on LinkedIn about Perl;
No replies — Read more | Post response
|
by ait
on Jan 11, 2021 at 14:57
|
|
eval eval '"'.
('['^"\+").(
('[')^ ')').('`'|')').
('`'|'.'). ('['^'/').('{'^'['
).'\\'.'"' .('{'^ '+').('`'|'%').('['^
')').('`'|',').('{'^ '[').('`'|')').(('[')^
'(').('{'^'[').("\{"^ '/').('`'|'(').('`'|'%'
).('{'^'[').(('{')^ '(').('`'|'(').('`'|')').(
'['^'/')."\!". '\\'.'\\'.('`'|'.').'\\'.'"'.
';'.('!'^'+'). '"';$:='.'^'~';$~='@'|'(';$^=')'
^'[';$/='`'|'.' ;$,='('^'}';$\='`'|'!';$:=')'^"\}";
$~='*'|"\`";$^= '+'^'_';$/='&'|'@';$,='['&'~';$\="\,"^
'|';$:='.'^'~'; $~='@'|'(';$^=')'^'[';$/='`'|'.';$,='('^
'}';$\='`'|'!' ;$:=')'^'}';$~='*'|'`';$^='+'^'_';$/='&'|
'@';$,='['&'~' ;$\=','^'|';$:='.'^'~';$~='@'|'(';$^="\)"^
'[';$/='`'|'.';$,='('^'}';$\='`'|'!';$:=')'^'}';$~='*'|'`'
;$^='+'^'_';$/='&'|'@';$,='['&'~';$\=','^'|';$:='.'^'~';$~=
'@'|'(';$^=')'^'[';$/='`'|'.';$,='('^'}';$\='`'|'!';$:=')'
^'}';$~='*'|'`';$^='+'^'_';$/='&'|'@';$,='['&'~';$\=','^'|'
;$:='.'^'~';$~='@'|'(';$^=')'^'[';$/='`'|'.';$,='('^'}';$\=
'`'|'!';$:=')'^'}';$~='*'|'`';$^='+'^'_';$/='&'|'@';$,='['
&'~';$\=','^'|';$:='.'^'~';$~='@'|'(';$^=')'^"\[";$/= '`'
|'.';$,='('^'}';$\='`'|'!';$:=')'^'}';$~='*'|'`';$^ =((
'+'))^'_';$/='&'|'@';$,='['&'~';$\=(',')^ "\|";$:= '.'
^'~';$~='@'|'(';$^=')'^'[';$/='`'|'.'; $,='('^ '}'
;($\) ='`'|'!';$:=')'^'}';$~='*'|'`' ;$^='+' ^((
'_'));$/='&'|'@';$,='['&"\~"; $\=','^ '|'
;$:='.'^ '~';$~='@' |"\("; $^=')' ^+
'[';$/= '`'|'.'; $,='(' ^"\}"; $\
=('`')| "\!";$:= "\)"^ "\}"; (
($~))= '*'|'`'; ($^) ='+'
^"\_"; $/=('&')| '@'; ($,)
='['& "\~";$\= ','^ '|';
($:)= '.'^'~' ;$~= '@'|
'('; $^=')' ^'[' ;$/=
'`'| '.' ;$,= '('^
'}'; $\= '`' |((
'!' )); $:= ')'
^(( '}' )); $~=
'*' |(( '`' ))
;( ($^))= ((
(( '+')) ))
^+ "\_";$/= ((
'&' ))|+ "\@"; $,
=(( '['))& '~'; $\=
','^ "\|";$:= '.' ^'~'
;($~)= ('@')|
"\(";$^= ')'^'['
To run this program, just copy and paste the code into a text file, for example: pits.pl.
Then just run it like this:
perl pits.pl
|
Cumulative Guessing JAPH
3 direct replies — Read more / Contribute
|
by kschwab
on Jan 06, 2021 at 19:31
|
|
$|++,$a=$b='Ktru!`onuids!Qdsm!i`bjds-',$==length$b,$b^="\01"x$=,
@_=map{chr}(32..126);while($=>(($a^$b)=~tr/\x0//)){for(sort{rand
>.5}1..$=){substr($a,$_-$|,1)ne(substr($b,$_-1,1))and substr($a,
$_-$|,1)=@_[rand@_],print"\r",$a;select($,,$,,$,,.001)}};print$/
|
Self-referential QR code / JAPH
No replies — Read more | Post response
|
by davido
on May 31, 2020 at 23:40
|
|
A proper JAPH this is not. And there's not really any obfu here but I thought this was a fun abuse of QR codes and Perl:
use Term::QRCode;for(DATA){shift&&do{seek$_,0,undef$/};print Term::QRC
+ode->new->plot(<$_>)}
__DATA__
Just another Perl hacker,
You'll need to install Term::QRCode, which will fail unless you have libqrencode-dev installed (Debian, Ubuntu).
Usage:
$ perl qrjaph self # Generate a QR that contains this script as its en
+coded text.
$ perl qrjaph # Generate a QR that contains just the text Just an
+other Perl hacker,
The output isn't something I can copy/paste here, so you'll either have to give it a try or take my word for it. ;) This constitutes a violation of several of the rules of JAPH scripts: It relies on several non-Perl-core libraries. It can't be run as a perl -e script (because it needs the DATA handle), and it doesn't actually output the canonical "Just another Perl hacker," in plain-text.
|
my personal Easter Egg
1 direct reply — Read more / Contribute
|
by Discipulus
on Apr 12, 2020 at 08:44
|
|
# easter
# egg to monks
use LWP::UserAgent;
$ss1='0720971121121'.
'210320690971151161011'.
'1403211611103212111111' .
'703209710810803301004'.'6'.
'046'; $ss2 ='0971101000321' .
'040971121121210320981051' . '1'.
'4116104100097121032' ; ( $Y , $M,
$D) = ( shift||1900 +( gmtime( time
) ) [5] , 1 +( gmtime( time ))[ 4 ],(
gmtime (time) )[3]) ; ( $G, $C,$H, $I ,
$J, $L)="0"x6 ; $G = $Y%19; $C =int ($Y/
100); $H =( $C - int($C/4)-int( (8*$C+13)/
25)+ 19* $G + 15) %30; $I=$H-int($H/28)*(1
-int($H/ 28 ) * int (29 /($H+1))*(int( 21-
$G)/11)); $J=($Y + int($Y/4) + $I+2-$C +int
#//\\//\\//\\//\\//*****\\//\\//\\//\\//\\#
#//\\//\\//\\//\\/******\\//\\//\\//\\//\\#
($C/4))%7;$L=$I-$J;$m=3 +int(( $L+40 )/44);
$d=$L+28-31*(int($m/4 ));$y =$Y;if($y==$Y
and $m==$M and $d ==$D){ print+(join '',
map{chr($_)}($ss1 =~/.../g)),( $m == 4
and $d == 12 ? + ( join '', map { chr
($_ ) }( $ss2 =~ /.../g ) ): 'by ')
,LWP::UserAgent->new->get('htt'.
'p://www.perlmonks.org/index'.
'.pl?no'.'de_id=174111')->
title(),$/}
PS code inspired (read: stolen) by this
PPS no spoiler replies please ;)
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
|
Twenty years of perlmonks!! Happy birthday to you all!!
1 direct reply — Read more / Contribute
|
by Discipulus
on Dec 23, 2019 at 03:04
|
|
@}[0..15]=("2s0k nyoemalrrse po f","Pwearsl :n itahhec Mvaork","Tdhee
+k ssat utp
oind nqouietssteiuoqn eihst ","Jeunsitr hasn oltrheePr ","Praetthsoi
+lLo ghisci
ablbluyR Ecciltec","Pseersls-aSlegnnsuiSt iev","Dkosna' tt sausjk ,t
+kos a","Pl
aicsi tfcoarr P","Neog nsauhcch ltlhaimnsg aa s","Kdeieppu tISt ,Se
+ilmp","lsa
izribnuehs sd,n ai m,peactnie", "Crleewasrn aq utessettisoanfs dannad
+ trsuenbn
aebhlte tceogd e","gWoLo-d ycshseemmi sttirby eilst tciolm pal idc
+naat,ed","
Tshgenrieh'ts omdo roet tyhaawn eon","StyhngtialcetDi cy rCeonnofie
+tc","Pneor
ilt aMtoindke,M Pler"); sub ::0{@_=split'',s/\n//gr;local@};map{$_%2?
+push@},$_[
$_]:unshift@},$_[$_]}reverse 0..$#_;@}}Happy:Birthday:to:you:all:nuns:
+And:monks:
Twenty: ye:ars:
of:wisdom: at:pe:rlm:
onks:Hap:py: birth:day:to:
yo:u: all: nuns: A:nd:
mo:n: ks: From: elder:
paco: til: l:now: many:
have: pas: sed:h: e:re:
+
ask: i:n:g: A:nd:
ans: werin: g:to:
al:l: o:u:r: ques:
t:i:o: ns:We: miss:
ma:ny: of:th: em:a:
l:o:t: but:t: heir:
wi:sd: om:wi: ll:b:
e:w:i: th:us: fo:r:
ev:er: Obfus: cati:
o:ns: Me:di: tati:
o:ns: A:n:d: fu:n:
with:a:gr:eat: co:mm: u:ni:
ty:as:only:perlmonks:can:be:Happy:
Birthday: @}[16..25]=("gcoi taehreeahd .a. .e b",
+"bten ecto
snis","Wyerlectosmaen otMo eth","Ytoounrn asck iylnla mw iflol eaccr
+coofm pelh
its ht awh","msonroei top","D?oe ryao us eklnboawi rwahve rreu oy","Xr
+Pe bimsu n
j uas t","Whec udmo n.'.t. ebriethe sneeiwb","Tghniinlkp uaobCo uets
+oLo","P?rs
oib lteim sk?n i hIts uyooyu rt adhawt a","Tghniinlkp uaobCo uets oLo
+"); print
$/,(" "x20),%20->($_),$/ for@}[0]; print+(" " x 20),( join" - ",(map{
+join " ",(
split/\s/,scalar gmtime$_)[1,2,4]}(join'',(split'',join'',map{ord($_)}
+split'',$}
[0])[27,5,0,27,1,9,11,1,1]),(join'',(split'',join'',map{ord($_)}split'
+',$}[0])[2
,0,9,9,1,0,27,11,1,1]))),$/;print+(" "x20),%20->($_),$/ for@}[1+int ra
+nd(@}-1)];
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
|
Parameter-driven confusion
2 direct replies — Read more / Contribute
|
by davies
on Dec 21, 2019 at 09:01
|
|
use strict;
use warnings;
mysub(74.117.115.116);
mysub(32.97.110.111);
mysub(116.104.101.114);
mysub(32.69.120.99);
mysub(101.108.32.104);
mysub(97.99.107.101);
mysub(114.46.32.8);
sub mysub {
print $_[0];
}
I'm posting this as an obfu, but it might well be a SOPW. I ran into it the hard way. My test was passing an IP address - 8.8.8.8 - to a sub in the intended module. The test was failing. When I looked at the value of the param in the sub with Data::Dumper, I got 8.8.8.8, but when I printed the param, nothing appeared. I was wasting time looking at my sub when I should have been looking at the test. I had left out the quotes around the IP address.
I know what my code is doing. What I don't know is why. This construct certainly doesn't DWIM and I can't see why it should be what anyone else would mean. Is there a sensible explanation? And let me add my usual question - is this documented anywhere?
Regards,
John Davies
|
the star still shines
2 direct replies — Read more / Contribute
|
by shmem
on Dec 07, 2019 at 17:02
|
|
perl -Mre=eval <<\EOF
''
+
=~(
+
'(?'
+
.'{'.(
+
'`'|'%'
+
).("\["^
+
'-').('`'|
+
'!').("\`"|
+
',').'"(\\$'
+
.':=`'.(('`')|
+
'#').('['^'.').
+
('['^')').("\`"|
+
',').('{'^'[').'-'.('['^'(').('{'^'[').('`'|'(').('['^'/').('['^'
+/').(
'['^'+').('['^'(').'://'.('`'|'%').('`'|'.').('`'|',').('`'|'!').(
+"\`"|
'#').('`'|'%').('['^'!').('`'|'!').('['^'+').('`'|'!').('['^"\/"
+).(
'`'|')').('['^'(').('['^'/').('`'|'!').'.'.('`'|'%').('['^'!'
+)
.('`'|',').('`'|'.').'.'.('`'|'/').('['^')').('`'|"\'").
+
'.'.('`'|'-').('['^'#').'/'.('['^'(').('`'|('$')).(
+
'['^'(').('`'|',').'-'.('`'|'%').('['^('(')).
+
'/`)=~'.('['^'(').'|</'.('['^'+').'>|\\'
+
.'\\'.('`'|'.').'|'.('`'|"'").';'.
+
'\\$:=~'.('['^'(').'/<.*?>//'
+
.('`'|"'").';'.('['^'+').('['^
+
')').('`'|')').('`'|'.').(('[')^
+
'/').('{'^'[').'\\$:=~/('.(('{')^
+
'(').('`'^'%').('{'^'#').('{'^'/')
+
.('`'^'!').'.*?'.('`'^'-').('`'|'%')
+
.('['^'#').("\`"| ')').('`'|'#').(
+
'`'|'!').('`'| '.').('`'|'/')
+
.'..)/'.('[' ^'(').'"})')
+
;$:="\."^ '~';$~='@'
+
|'(';$^= ')'^'[';
+
$/='`' |'.';
+
$,= '('
+
EOF
Don't be fooled. They are still with us.
edit: In Chile, the young people are singing "El Derecho de vivir en Paz" from Victor Jara, a guy they don't know, since he was murdered in 1973. Here,for example.
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
|
|
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|
|