Live data from Hacker News

Perl secret operators and constants

search.cpan.org

31–40 of 46 posts

Re: Perl secret operators and constants

#32
post #30

I wonder how many other languages have well-known secret operators? I know of C's secret "limit" operator: int x = 10; while (x --> 0) { printf("%i", x); } prints 9876543210 Of course, in some ML dialects you can define your own opreators - such as (f |> g) to mean (g o f) which is actually very useful.

That's not an operator, it's just precedence rules. while ((x--) > 0)

None of these secret operators are actual operators.

(Some of them aren't even collections of operators - }{ is a form of code injection, and the > thing has only one operator, applied to a string and a regex.)

Re: Perl secret operators and constants

#34

if nothing else, most of these operators have immense nicknames. Now I just need an excuse to involve a flaming x-wing in my code... Operator Nickname Function ====================================================== 0+ Venus numification @{[ ]} Babycart list interpolation !! Bang bang boolean conversion }{ Eskimo greeting END block for one-liners ~~ Inchworm scalar ~- Inchworm on a stick high-precedence decrement -~ I…

When I first learnt perl, twenty years ago, I loved it because it was full of clever devices and syntactic virtuosism. Now, I don't like it anymore exactly for the same reason. It's cool, but the wrong kind of cool.

Re: Perl secret operators and constants

#35
The ones that I occasionally use:

0+ - venus - numification: When you really need a scalar value to be represented as a number and not as a string. Useful when you're generating JSON and you need the types to be correct.

@{[ ]} - baby cart - list string interpolation: This is very useful when you need to interpolate arbitrary expressions inside a list. Useful when you're generating an SQL query, for example:

  SELECT * FROM Office WHERE id IN (@{[ join(',', ('?') x @ids) ]})
!! - bang bang - boolean conversion: When you want to return a boolean value from a function, but you don't want to leak implementation details.

,=> - winking fat comma - non-stringifying fat comma When you want to create a hash whose keys are constants.

Re: Perl secret operators and constants

#36
post #8

It's articles like this that give Perl a bad reputation.

it's the existence of this that gives Perl a bad reputation. You can write Perl as though it were Python. In the Perl world that's called "baby talk" https://www.google.com/search?q=perl+"baby+talk" in the real world it's called clean, maintainable code.

I think there's a difference between "baby talk" and using Perl as Perl.

You can write Perl that looks like Python, or C, or whatever, but you're missing out on what makes Perl, Perl.

"baby talk" Perl is another name for being able to much with Perl, knowing very little of it. Also known as, "Getting your job done".

It's up to the individual to learn more about the language, which can be done gradually, much like a natural language.

"Clean, maintainable code" in Perl is actually known as, "Modern Perl" [0]

[0] http://modernperlbooks.com/

Re: Perl secret operators and constants

#37
post #8

It's articles like this that give Perl a bad reputation.

it's the existence of this that gives Perl a bad reputation. You can write Perl as though it were Python. In the Perl world that's called "baby talk" https://www.google.com/search?q=perl+"baby+talk" in the real world it's called clean, maintainable code.

Being able to write "good Perl" doesn't speak to the likelihood of such being created; writing good Perl is an uphill battle at the cost of self-discipline, which is finite.

Re: Perl secret operators and constants

#38

Earlier quoted context omitted.

it's the existence of this that gives Perl a bad reputation. You can write Perl as though it were Python. In the Perl world that's called "baby talk" https://www.google.com/search?q=perl+"baby+talk" in the real world it's called clean, maintainable code.

I think there's a difference between "baby talk" and using Perl as Perl. You can write Perl that looks like Python, or C, or whatever, but you're missing out on what makes Perl, Perl. "baby talk" Perl is another name for being able to much with Perl, knowing very little of it. Also known as, "Getting your job done". It's up to the individual to learn more about the language, which can be done gradually, much like a n…

you're wrong though: it's not just up to the individual to learn more about the language, it's also up to to every single person who maintains that code afterward! If you learn something, you force your maintainer to learn it.

This is particularly true because many syntax elements are literally impossible to Google. If you didn't happen to learn some idiom (syntax), you just can't deduce or discover what it does, unless a comment precedes it exactly listing the effect.

This is just the nature of Perl.

Re: Perl secret operators and constants

#39
post #13

Interesting, but the title is misleading. They aren't operators, but rather mostly combinations of operators with potentially useful side effects.

Clearly you didn't read the DESCRIPTION section.

A description section doesn't change the fact that the title is misleading. Clickbait is clickbait.

Re: Perl secret operators and constants

#40
post #34

if nothing else, most of these operators have immense nicknames. Now I just need an excuse to involve a flaming x-wing in my code... Operator Nickname Function ====================================================== 0+ Venus numification @{[ ]} Babycart list interpolation !! Bang bang boolean conversion }{ Eskimo greeting END block for one-liners ~~ Inchworm scalar ~- Inchworm on a stick high-precedence decrement -~ I…

When I first learnt perl, twenty years ago, I loved it because it was full of clever devices and syntactic virtuosism. Now, I don't like it anymore exactly for the same reason. It's cool, but the wrong kind of cool.

That's exactly the problem with Perl: cleverness -- especially other people's "cleverness" -- gets to be tedious, if not an outright pain to put up with and maintain, after a while.
Post reply on HN