3 ms·
>As if they wanted to win an obfuscation contest and succeeded. Have you used Perl? I think it would win that contest. Here is an example: my %author;
by xupybd 4y ago
>As if they wanted to win an obfuscation contest and succeeded.
Have you used Perl?
I think it would win that contest. Here is an example:
my %author;
while (<FH>) {
next unless /^\d{6}=[^|]+\|/;
my($l, $r) = split /=/, $_, 2;
$author{$l} = [ split /\|/, $r, 2 ];
}
- autoexec 4y agoPerl gets trashed a lot for how unreadable it is, but examples that aren't intentionally written to be as obfuscated as possible are often just examples of how ugly regular expressions are. For people who understand regular expressions and understand how they are used in perl it's not as hard to read/follow as it looks. Perl certainly has a few features that don't help its reputation (like the extremely useful '$_') but it gets more hate than it deserves. It's still my language of choice when it comes to regex heavy projects. That said, if your goal was to write obfuscated code, perl wouldn't be a bad choice!
- wruza 4y agoYes. Even made job-related tools in it, and was looking forward to perl 6 as a fix-it-all version. There is no value in %<${, and it could look like let author = {} for (let line in stdin.lines()) { if (not line.m(/…/)) next let [l, r] = line.split('=', 2) author[l] = r.split('|', 2) } The key feature of perl is basically inline regexps. Everything else is an unnecessary noise. qx{…} -> sh("…"), bless -> class, etc. I loved perl and still know it, but haven’t written a single line in 17 years because there was no reason.
- jstanley 4y agoWhat's wrong with that? (Apart from using a bareword filehandle, and weird spacing on "my($l, $r)"). It does exactly what it says.
- xupybd 4y agoTry to find a new user of Perl that can understand this split /=/, $_, 2; So they don't and they look up the split function to find out. Okay now they have most of it from https://perldoc.perl.org/functions/split https://perldoc.perl.org/functions/split But what is that $_ thing? Hmmm... Okay now I've found that it's one of these global variable things https://perldoc.perl.org/variables https://perldoc.perl.org/variables Then you look at the author hash. First it has a % in the front. But now its a $ . Okay so now you read through the docs again. https://perldoc.perl.org/perldata https://perldoc.perl.org/perldata Not totally there yet you have to learn about references https://perldoc.perl.org/perlref https://perldoc.perl.org/perlref It's just so much noise.