13 ms·
Secret Perl Operators
- elblanco 17y agoOh Perl, will you never stop being a source of witty fun?
- DougWebb 17y agoMany of these don't pass muster as Modern Perl development, or any professional software development. As a code reviewer, I'd reject everything but <=> and @{[ ... ]} as being too cryptic. <=> passes because it's the standard way to compare numbers in sort routines, and @{[ ... ]} passes because it's the standard way to interpolate lists and function call return values into strings. }{ Useful for one-liners, but has no use in production code. =()= In production code, I'd prefer to see the match results assigned to a named array, and the array used in a scalar context to get the length. Alternatively, I'd accept a comment explaining why there is an assignment to an anonymous array. It had better not call =()= an operator, though. ~~ You can force scalar context using the scalar keyword, which is much clearer. ~- You can type $x-1, which is much clearer and works for numbers <= 0 too. -+- I didn't know "3.99" was an integer... in any case, would probably use printf or sprintf for formatting numbers for display, using explicit formats rather than relying on whatever -+- spits out. 0+ Again, I would use printf or sprintf in most cases where 0+ might be used.
- SwellJoe 17y ago}{ Useful for one-liners, but has no use in production code. What about production one-liners? Let us not underestimate the power of a well-applied one-liner.
- pkrumins 17y agoWell said!
- joe_the_user 17y agoI wouldn't underestimate the power of a one-liner. That's why I'd avoid using one! With great power comes great responsibility - and it's hard to cram the responsibility part into one line as contrasted with a clear, well-behaved subroutine.
- ramchip 17y agoI think this is tongue in cheek. Just re-read: Compare these two examples: print "these people @{[get_names()]} get promoted" and print "these people ", join " ",get_names(), " get promoted" Clearly, the first example wins for code clarity.
- pkrumins 17y agoThanks for the comments. I fixed the wording mistake of 3.99 being an integer. You are right about everything you say. @{[]}, <=>, and =()= are acceptable in production code, but the others are not. These other "operators" actually were invented to chop off characters in Perl Golf competitions. This article wasn't meant as "good Perl coding tips and tricks", it was more written for fun.
- mst 17y agoI tend to prefer using ${\...} for interpolation - so print "${\join ',', @array}"; or so. See http://shadowcat.co.uk/blog/matt-s-trout/madness-with-methods http://shadowcat.co.uk/blog/matt-s-trout/madness-with-method... for more fun you can have like this. Oh, and remember - sometimes makefiles that do useful things to and with production code should contain one liners. Don't assume that the intersection of "one liner" and "production" is zero - when I ran the Web Server Survey at Netcraft about 3/4 of it was one liners driven by make ...
- fdgfdgfd 17y agohttp://www.wowcool.org http://www.wowcool.org The website wholesale for many kinds of fashion shoes, like the nike,jordan,prada,adidas, also including the jeans,shirts,bags,hat and the decorations. All the products are free shipping, and the the price is competitive, and also can accept online payment.,after the payment, can ship within short time. ====> free shipping <==== ====>competitive price<==== ====>any size available<==== ====>accept online payment<==== http://www.wowcool.org http://www.wowcool.org
- pmorici 17y agoAlternate title: "8 Reasons Not to Use Perl". Why do people who use Perl get such a kick out of junk like this.
- berntb 17y ago>> Why do people who use Perl get such a kick out of junk like this. Alternative question from the last half dozen times I've seen Perl mentioned in a good light on HN: Why do Python/Ruby/X people get such a kick out of language wars? It was well formulated here: http://news.ycombinator.com/item?id=963706 http://news.ycombinator.com/item?id=963706
- gaius 17y agoIt's a cultural thing. Python people value doing complicated things with simple code. Perl people value doing simple things with obscure language features, then basking in the glow of being called a "wizard". In other words, every other language community cares more about what you do than how you do it.
- gloob 17y agoThe question was: Why do Python/Ruby/X people get such a kick out of language wars? Your response was: Python people value doing complicated things with simple code. Perl people value doing simple things with obscure language features, then basking in the glow of being called a "wizard". Methinks there's a disconnect somewhere here.
- henning 17y agoIt's official, Haskell's boob combinator, (.) . (.), has competition. From the Goatse operator.