I can write readable Perl by writing it as if it were Python, adding extra braces where required, a couple of use declarations at the top, and wrapping some system functions with clearer names. But if that's what you want then it's easier to just write Python. Perl's USPs like regex literals and $_ rely on you writing in an unreadable style.
So, Python regexps are suddenly more readable, even though they need
additional layer of backslashes?
$_ does not rely on unreadable style. First, it's a common idiom, so it's in
no way less comprehensible than list comprehension in Python. You just need to
understand what it means. Second, it's not an obligation to use $_. I often
avoid it if it doesn't make my code reflecting my intentions better. Funny
thing, I do the same in Python, C, and Erlang.
And I hear about $_ and regexp literals as unique selling points (if I read
your acronym correctly) only from people that don't really write in Perl.
> So, Python regexps are suddenly more readable, even though they need additional layer of backslashes?
Python encourages a style that makes less use of regexps. (And you don't need extra backslashes, you can use r'...').
> And I hear about $_ and regexp literals as unique selling points (if I read your acronym correctly) only from people that don't really write in Perl.
Nice ad hominem. Go on then - what's your USP for Perl? Why should one use it over Python/Ruby/...?
> Python encourages a style that makes less use of regexps.
Yes, even in the places where regexp would help very much. And even if you'll
insist on using regexps, Python makes them highly inefficient or cumbersome
(or both), because if you're careful, you'll either get code that needs to
store compiled pattern somewhere vaguely related to the code at hand, or code
that compiles the pattern on every use. If you are not careful enough, you'll
get the two at the same time.
> Nice ad hominem. Go on then - what's your USP for Perl? Why should one use it over Python/Ruby/...?
Thank you, though I wasn't refering to yourself. It was pretty clear you don't
write Perl much.
My reason to use it is because it was my primary language for over a decade.
For other people? I don't know. All three are similar in what they can do and
how does it look afterwards, as all of them are scripting languages in OOP
land.
Combine that one and Perl's learning curve, and you'll get why Perl usage was
declining over the last decade.
"_" in Scala is not a magic variable like in Perl. It's a very mechanical syntax transformation, it just expands to "x => x" (or equivalent, and without colliding with any "x" that's already defined).
In practice maybe the use is similar. But having a comprehensible theoretical model makes all the difference in terms of making sure you can actually read the code and understand what will happen.
There is nothing particularly magical about $_. It is merely a global variable that is optionally used implicitly in various builtins, as well as scope-localized by loop control constructs.
That depends on how you define "magic". I typically do so as "cannot be implemented in the language itself", which does not apply to $_, as it can be reimplemented in Perl itself. If i was bored enough i could create a module that sets up a $this variable that acts exactly the same, in pure perl.