My first JAPH
No replies — Read more | Post response
|
by Zarabozo
on Jun 06, 2014 at 07:13
|
|
|
This is my first JAPH. I'm very passionate about Perl and I thought I had to make at least one in my life. It's probably not a very good one and will seem very rookie for many - but then again, it's my first one and it's a start for me. :-)
BEGIN{*{0}=sub{print@
_};*{1}=sub{& #@_=__;
0 # print ord sqrt(e)
(chr 32)};my$v=chr 97
;* #$%&&oo11||s/\e\//
{'::'.++$v}=do{my$ #?
v=$ #v?a:b?v:a?:v:a?c
v;sub{&0($v)};}until$
::{v};}($_=q;kvtu1bop
uifs1qfsm1ibdlfs;)=~s
/(.)/&$1/xeg;eval for
$ # while(1){::{___}}
_ =~ /.{2}/g;__END__;
|
Fork Sort
1 direct reply — Read more / Contribute
|
by BenGoldberg
on May 31, 2014 at 17:35
|
|
|
Put the following in a file,
defined(my $v = <>) or exit;
my ($c,@c) = 1;
open($_, "|-", "$^X $0") for @c[0,1];
$_ eq $v ? ++$c : print { $c[ $_ lt $v ] } $_ while <>;
pop @c;
print $v x $c;
, and run it with an unsorted text file either on stdin,
or as a command line argument.
The output will be sorted.
|
I love Perl to bits
No replies — Read more | Post response
|
by FloydATC
on May 09, 2014 at 08:58
|
|
|
#!/usr/bin/perl
use strict;
use warnings;
my$pq=$[;my$qp=!$_;$"='@';for$/(split//,".,., ,,..,,,, .....,, '.,,,
.,.,., .,.,, '.,..,,,, ...., ,.,,...,. ,,, ...,.,, ',.,,, .,.,..,
..,,, '.,,..,., .,'...,,, '..,,,, .,...,, .,,'...., ..,..,., ., '...,
'.,,, ',,,., .',,,,*"){print$/eq'.'?foo(!$pq):($/eq'\''?bar(!$"):($/eq
','?baz(!$qp):$"));}sub foo{$pq+=$qp+sqrt($=+4);$pq%=($=+4)/2**3;$!;
}sub bar{$qp*=-1;$!;}sub baz{my@s=split//,unpack'b8',$";$s[$pq]=1-$s[
$pq];$"=pack'b8',join'',@s;$pq+=$qp;$pq%=$=/7.5;$!;}
-- FloydATC
Time flies when you don't know what you're doing
|
Stumbled upon Inline::C
No replies — Read more | Post response
|
by sealingcat
on May 02, 2014 at 01:45
|
|
|
I recently discovered that OSX 10.7+ with Xcode has Perl configured with Inline::C. To celebrate I wrote this.
#!/usr/bin/perl
use Inline C=>q{const r[]={451418730,74<<24,544502645,1953459809,
544367976,1819436368,1667328032,745694571,1086337290,193204112,53
<<25,1342484481,3296952525,828293904,1523056639,1208,3271888642};
int g(){((int(*)())r)();}};g
This isn't really all that obfuscated. (Un)Fortunately it only runs on OSX 10.7+ with Xcode (x86 or amd64).
|
BIDI JAPH
No replies — Read more | Post response
|
by BenGoldberg
on Apr 18, 2014 at 22:51
|
|
|
binmode STDOUT, ":utf8";
my @o = ("\x{202d}", "\x{202e}");
print "$o[--$|]$_" for split //,
'J,ursetk cAanHo tIhDeIrB /Pler';
The actual output will be:
J,ursetk cAanHo tIhDeIrB /Pler
If your terminal has proper unicode bidi support, it should look the same as:
Just Another Perl/BIDI Hacker,
|
Is there a non-empty error quine in perl?
4 direct replies — Read more / Contribute
|
by ambrus
on Mar 08, 2014 at 19:59
|
|
|
Can you give a non-empty error quine for perl? By an error quine, I mean a perl script that, when ran perl, prints exactly the same bytes to its standard error as its source code and nothing on its stdout. The printout shall be an error message coming from the perl core (or maybe a core module), not eg. something explicitly printed with a die or print statement in the source code. The program shall be ran by redirecting it to the stdin of perl, invoked without any switches.
If there is such an error quine, please give one, preferably an elegant one which doesn't seem like cheating. Please tell what version of perl the script works with.
As an example that doesn't work, take the following script:
Number found where operator expected at - line 1, near "line 1"
(Do you need to predeclare line?)
If you run this with perl 5.16.3, you get the same error message as the source, but then get other error messages too, so this isn't an error quine.
Update: asked for perl version.
Update: ais523 says these are called “Kimian quines”
|
Perl Python Partial Polyglot
4 direct replies — Read more / Contribute
|
by kschwab
on Jan 22, 2014 at 14:38
|
|
|
Runs under perl and/or python and produces *almost* the same output...
0 and chr <<1;
'''#'
1
use strict;use warnings;
sub perl{
map{m&${\uc(q,m,)}&&&($,.=$_,)=~s,[^A-z0-6],,xg}@_;($_=$,)
=~tr$A-Za-z0-9+,$ -_$;for(unpack("u",join('',map(chr(32+
length($_)*3/4).$_,m$(.{1,60})$gs)))){$.='$_'.'="';map
{$..="\\$_"}unpack('(a3)*',$_.'012');$..='"';eval(${\$.}),
s;\x50++\S{5}+;\u${\substr((caller(0e0))[0b11],-4)
};;print}}${{}={<<'1<<1'=>1}
#'''
l=('137137151155160157162164137137''050047142141163145066064047051',
'161056142066064144145143157144''145050143051',
'MTEyMTY1MTYzMTY0MDQwMTQxMTU2MTU3MTY0'
'MTUwMTQ1MTYyMDQwMTIwMTcxMTY0MTUwMTU3'
'MTU2MDQwMTUwMTQxMTQzMTUzMTQ1MTYyMDU0'
)
def l1(l):[(yield'\\'+l[i:i+(2|1)])for i in xrange(0,len(l),(2|1))]
i,I=lambda l:eval('"'+''.join(list(l1(l)))+'"'),lambda l:eval(i(l))
c,q=l[0o0+-0o1],I(l[0o1&0o2]);print(i(I(l[-(0o3^0o1)],)))
'''
1<<1
and 1;
perl(split/\n/,(keys(%{${{}}))[0])
#'''
Note: edited 11/23/18 to fix error about keys() on a scalar.
|
Strict;ly Awful q's
No replies — Read more | Post response
|
by kschwab
on Jan 17, 2014 at 18:26
|
|
|
use warnings; complains, but use strict; is happy.
#!/usr/bin/perl
use strict;
package q;
sub ::_{
$,{q;,;}=q,35787677-758717277656275-741627569-76558606862755',
;$;;$,.=pack(q,c*,,,map ($_-42+unpack(q,c,,,uc(q;q;)),
unpack('(A2)*',($,{','}))));{{},print(q//,$/);q}}}}q;
q-main::q--;>_(@_,q,,,);q}
}
|
$|-- rocks.
1 direct reply — Read more / Contribute
|
by BenGoldberg
on Jan 03, 2014 at 22:30
|
|
|
sub _{@_<2&&return print@_;my@a;push@{$a[$|--]},$_ for
@_;_(@$_)for@a};_ split//,"huroP cels,tetah Jen akrr";
|
2014 Code Golf Challenge
6 direct replies — Read more / Contribute
|
by tobyink
on Jan 01, 2014 at 06:46
|
|
|
There's a 2014 themed golf competition on Stack Exchange. The challenge is to print the characters "2014" without using any digits in your source code.
Sadly using the N'Ko letter "ka" is ruled out because it would require use utf8 (which includes the digit "8").
My solution is 17 characters. If you swap print for die you can reduce it by two characters, but I consider that to be a cheat.
print RPQT^'````'
Can anyone improve upon it?
Update: a one character improvement:
print'````'^RPQT
use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
|
|