Dying for a Nice Japh
liverpole
created: 2006-01-28 19:09:55
This runs under Linux, using an obscure trick which I've never seen used before.

Using -MO=Deparse won't really help.  Anyone interested in providing an analysis?

#!/usr/bin/perl -w

%ENV = qw(
	bin 42 perl 52 my    33 opt   26 lib  32 site 25 tmp 34 
	usr 22 var  62 local 36 other 44 misc 12 temp 45
);


@INC = (
	"./opt/usr/usr/tmp/opt",
	"/perl/lib/usr/usr/72",
	"/perl/lib/usr/tmp/bin",
	"/usr/misc/lib/usr/var/lib",
	"/my/54/other/bin",
	"./tmp/lib/usr/tmp/opt/misc/usr/opt/site",
	"/usr/usr/23/misc/usr/usr/lib/lib/usr/usr/var/usr",
	"/opt/usr/13/usr/usr/lib/local/24/temp",
	"/usr/usr/usr/usr/usr/usr/lib/lib/usr/usr/var/usr",
	"/usr/usr/usr/usr/tmp/bin/lib/usr/opt/usr/usr",
	"./site/local/site/lib",
	"/usr/usr/usr/var/usr/usr",
	"/site/tmp/temp/lib",
	"/usr/var/var/usr/usr",
	"/usr/66/usr/usr/site",
	"./usr/usr/tmp/other/lib/usr/opt/site",
	"/usr/usr/usr/usr/usr/usr/usr/misc/lib/var/usr",
	"/opt/opt/usr/64/other/temp",
	"/usr/usr/usr/usr/usr/usr/usr/misc/lib/var/usr/lib/usr/usr",
	"/usr/usr/usr/usr/tmp/lib/usr/opt/usr/usr/lib/usr/usr",
);



map  { $, = $_; map { $, =~ s/$_/$ENV{$_}/g } (keys %ENV); $_ = $,} @INC;
map  { s,^\.,$/, } @INC; map { $; = 101+int($_/5)+($_>14);
map  { s,/(\d)(\d),' 'x$1."\e[$;m".'#'x$2."\e[m",eg } $INC[$_] } (0..19);
@INC = ((join $/,@INC),$/);


eval { require "JAPH" };

die


@ARGV=split//,"/:L"; map{print substr crypt($_,ord pop),2,3}qw"PerlyouC READPIPE provides"
Re: Dying for a Good Japh
created: 2006-01-30 09:45:47
Quite nice.

Set a number of environment vars to selected numbers.

Set @INC to carefully constructed rubbish.

Convert @INC to print JAPH in big letters using environments set earlier. This seems to use ANSI/terminal control sequences.

Ask to load a module. This will fail so perl will print out @INC now holding the message.
On Solaris the eval is not needed and the module could be anything.

A nice trick would be to leave the real @INC in place in some form so real modules would work but require "JAPH" would give message.

Re^2: Dying for a Good Japh
created: 2006-01-30 10:57:12
Thanks for the good analysis ++.

You're correct about not needing the eval.  I left that in because it was how I discovered the trick of doing a require followed by die in the first place, when working on code that needs Win32::CONSOLE::ANSI, but only on Windows.  When debugging the program by putting die in the middle, I was surprised that it died with the error I had circumvented with the eval.  Looking up die, quickly set me straight that the behavior was correct.

Besides the double entendre on "Dying for a Good Japh", I like the irony that the program complains it can't find JAPH in "Just Another Perl Hacker"!


@ARGV=split//,"/:L"; map{print substr crypt($_,ord pop),2,3}qw"PerlyouC READPIPE provides"
Re^3: Dying for a Good Japh
created: 2006-01-31 05:41:59
The die doesn't seem to be required either.

I think there is an implicit "die" in the error that it can't find the module.

Re^4: Dying for a Good Japh
created: 2006-01-31 10:30:13
    I think there is an implicit "die" in the error that it can't find the module.

No there isn't.  If eval is used, taking out die will cause the output to cease appearing.  Try it and see...


@ARGV=split//,"/:L"; map{print substr crypt($_,ord pop),2,3}qw"PerlyouC READPIPE provides"
Re^5: Dying for a Good Japh
created: 2006-02-02 05:35:38
True but I'd already taken out the eval.

I guess it depends on what else you are doing. The eval stops the module load fail from dieing. This allows other lines to be added to the program which will run. When the die is hit the JAPH prints.

...
eval {require "JAPH"};
print "Hello mum!\n";
die

OUTPUT
Hello mum!
Can't locate JAPH in @INC ...
...
) at test.pl line xx
       ... propagated at test.pl line yy.

perlmonks.org content © perlmonks.org and liverpole, tweetiepooh

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03