3 ms·
People think Perl code is unreadable and mysterious because the language design philosophy is different than other programming languages. Most languages strive
by daotoad 10y ago
People think Perl code is unreadable and mysterious because the language design philosophy is different than other programming languages. Most languages strive for a limited, orthogonal set of built-ins and features without any repetition. Most languages enforce opinions about how things like OO and function calls are going to work.
Perl is designed to be maximally expressive. It is designed to be instantly familiar to someone who writes shell script, uses sed and/or awk and writes C for Unix environments. If you don't have this background, it can be a lot to absorb.
Here are some big things that Perl outsiders find troublesome at first glance:
1. Sigils are mysterious and scary--other languages don't have them. In practice, they're rather nice--they distinguish between functions and variables. They act sort of like a minimalist form of hungarian notation.
2. Built in regexes. Regex syntax is dense and messy. Putting it right in the language makes them easy to use. It also can make things hard to read. Perl didn't invent regexes and tt hasn't stopped most languages from implementing regex libraries. That's why Perl offers the expanded syntax that makes it easy to document complex regexes.
3. Special variables - $_, @_ are odd enough, but when add in the whole panoply from perlvar, it's pretty gross. In reality you really only need to know a few ($_, $@, @_, and $! are the only ones I use regularly), but they are terse and must simply be memorized.
4. Function calls in Perl are weird. Most people use one of the two common forms of argument unpacking that give you pass by copy semantics, but you can also pass by reference. Once you get the hang of it, it's not that complicated, but it is different and can be more than a little confusing for newbies.
5. List flattening. When you call a function like so: foo( @bar, %baz, $qux ), it gets one big list of arguments, the members of @bar and %baz get expanded. It's sort of the opposite of destructuring on assignment.