LWN.net Logo

OpenBSD 4.1: Puffy Strikes Again (O'ReillyNet)

OpenBSD 4.1: Puffy Strikes Again (O'ReillyNet)

Posted May 5, 2007 18:05 UTC (Sat) by Richard_J_Neill (subscriber, #23093)
In reply to: OpenBSD 4.1: Puffy Strikes Again (O'ReillyNet) by khim
Parent article: OpenBSD 4.1: Puffy Strikes Again (O'ReillyNet)

There are several issues here.

1)Can perl be obfuscated/hard to read? Yes. For example, this construct which I saw on slashdot as a signature.

perl -e'$_=q#: 13_2: 12/o{>: 8_4) (_4: 6/2^-2; 3;-2^\2: 5/7\_/\7: 12m m::#;y#:#\n#;s#(\D)(\d+)#$1x$2#ge;print'

That's the origin of the "write-only code" or "programming in line-noise" jokes. But then, any language allows this.

2)Can perl be clearly written and understandable. Yes, of course - it depends on the style of the author. (It also helps to avoid some of the more obscure syntax).

3)Can you write a trojan in perl, which will fool casual inspection of the source. Yes. But you can do it in C, or bash too. Eg:

if ((a=b))... /* = vs == */

:(){ :|:& };: #Do NOT try this in bash, it will hang your system.


(Log in to post comments)

This has nothing to do with OpenBSD.

Posted May 5, 2007 18:22 UTC (Sat) by smoogen (subscriber, #97) [Link]

My only issue with write-only-code was that for a long time it was the preferred religion of many perl coders. Maybe it was job-security fears or the macho-ness that none of the other perl coders could figure out your hairy construct you came up with. This is not a language issue though.. it is a culture/religion issue and those are the ones that get people the most rankled... got to know who your buddies are and who you need to send the inquisition after...

Just fun

Posted May 5, 2007 18:45 UTC (Sat) by niner (subscriber, #26151) [Link]

I often try to solve some thing with as little lines of code or even characters as possible in Perl - and then throw this code away and replace it with a longer, maintainable version. It's just fun and nice practice, not unlike something mathematicians do.

To introduce such constructs into production code is irresponsible of course.

OpenBSD 4.1: Puffy Strikes Again (O'ReillyNet)

Posted May 6, 2007 7:55 UTC (Sun) by jengelh (subscriber, #33263) [Link]

>perl -e'$_=q#: 13_2: 12/o{>: 8_4) (_4: 6/2^-2; 3;-2^\2: 5/7\_/\7: 12m m::#;y#:#\n#;s#(\D)(\d+)#$1x$2#ge;print';

And for those stuck with such, try this:

perl -MO=Deparse -e '$_=q#: 13_2: 12/o{>: 8_4) (_4: 6/2^-2; 3;-2^\2: 5/7\_/\7: 12m m::#;y#:#\n#;s#(\D)(\d+)#$1x$2#ge;print';
$_ = ': 13_2: 12/o{>: 8_4) (_4: 6/2^-2; 3;-2^\\2: 5/7\\_/\\7: 12m m::';
tr/:/\n/;
s/(\D)(\d+)/$1 x $2;/eg;
print $_;

It's so much easier to read, so why not use it should you stumble across such code.

OpenBSD 4.1: Puffy Strikes Again (O'ReillyNet)

Posted May 8, 2007 11:28 UTC (Tue) by nix (subscriber, #2304) [Link]

The shell won't like that: you open a ' quote and then close it in the middle of the block...

OpenBSD 4.1: Puffy Strikes Again (O'ReillyNet)

Posted May 8, 2007 11:32 UTC (Tue) by jengelh (subscriber, #33263) [Link]

13:26 takeshi:~ > echo 'a''b''c'
abc

OpenBSD 4.1: Puffy Strikes Again (O'ReillyNet)

Posted May 8, 2007 11:41 UTC (Tue) by nix (subscriber, #2304) [Link]

I don't see the relevance of that: there are no doubled quotes in the parent of your post. Everything from the third line onwards is *typed to the shell* because the ; on the previous line terminated the *shell's* command line, not perl's (you just closed the quote that would have protected the ; from the shell).

I don't think the shell likes

$_ = ...

as syntax very much.

OpenBSD 4.1: Puffy Strikes Again (O'ReillyNet)

Posted May 8, 2007 11:44 UTC (Tue) by jengelh (subscriber, #33263) [Link]

I thought you could figure out that the bold text is what you type, and the non-bold text is what you get. :-)

OpenBSD 4.1: Puffy Strikes Again (O'ReillyNet)

Posted May 8, 2007 18:37 UTC (Tue) by nix (subscriber, #2304) [Link]

Oops, sorry, reading with links; no bold :) I see it with one of those
newfangled graphical browser thingies.

OpenBSD 4.1: Puffy Strikes Again (O'ReillyNet)

Posted May 10, 2007 10:28 UTC (Thu) by ekj (subscriber, #1524) [Link]

Any language *CAN* be obfuscated. However some obfuscate easier than others, and there are no other language where such a large set of coders took so obvious pride in unreadable gobbelydok. "Perl oneliner" anyone ?

It's more a question about culture than about the language as such really, allthough it *does* help the confusion and illegibility when you have a dozen or more "special" characters with various magical properties -- for added bonus, let their magical properties be dependent on context.

Copyright © 2008, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds