I've seen many (code-golf) Perl programs out there and even if I can't read them (Don't know Perl) I wonder how you can manage to get such a small bit of code to do what would take 20 lines in some other programming language.
I'd like to learn how to write powerful and yet short programs like the ones you know from the code-golf challenges here. What would be the best place to start out? I don't want to learn "clean" Perl - I want to write scripts even I don't understand anymore after a week.
If there are other programming languages out there with which I can write even shorter code, please tell me.
In 2020, it's easy to write off Perl as a language whose heyday has passed. But the reality is that, more than thirty years after its first release, Perl remains not only alive but still evolving (hello Perl 7!).
In bioinformatics, where Perl's position as the most popular scripting language powered many 1990s breakthroughs like genetic sequencing, Perl has been supplanted by Python and the statistical language R (a variant of S-plus and descendent of S, also developed in the 1980s).
The Python applications are being rewritten in Java because of maintenance issues (mainly caused by lack of proper typing). Python does not rule here. You might want to try Ruby for some of those things you reached to Python for. It takes direct inspiration from Perl and does a lot of those things better, IMO.
Perl dropped to an all-time low on the most recent TIOBE Index that ranked the 20 most popular programming languages.
There are a number of factors that make Perl good for code golfing:
$_
if no argument is specified. (A few act
on @_
.)split
) often have defaults that
let you omit some arguments or even all of them.<>
.map
and grep
Additionally, without strictures (which are off be default):
undef
becomes either 0
or ''
depending on context.Now that that's out of the way, let me be very clear on one point:
Golf is a game.
It's great to aspire to the level of perl-fu that allows you to be good at it, but in the name of $DIETY
do not golf real code. For one, it's a horrible waste of time. You could spend an hour trying to trim out a few characters. Golfed code is fragile: it almost always makes major assumptions and blithely ignores error checking. Real code can't afford to be so careless. Finally, your goal as a programmer should be to write clear, robust, and maintainable code. There's a saying in programming: Always write your code as if the person who will maintain it is a violent sociopath who knows where you live.
So, by all means, start golfing; but realize that it's just playing around and treat it as such.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With