
Perlsecret - Perl secret operators and constants - yurifury
http://search.cpan.org/~book/perlsecret-1.001/lib/perlsecret.pod#NAME
======
pyre
This fails to mention the most useful part of the "baby cart":

    
    
      "Greetings @{[ get_planet() ]}lings, we come in peace!"
    

Evaluating functions directly inside of a string. It's sort of alluded to with
"@{[ keys %hash ]}", but in doesn't come right out and say it.

~~~
btilly
You get the wrong context when you do that. Try it with, say, localtime and
see what happens. String interpolation is more obvious, and only one character
more in normal formatting, one character less in golf:

    
    
        "Greetings " . get_planet() . "lings, we come in peace!"
    

As it says, the whole point of the baby cart is to force list interpolation.
If you don't specifically want that, don't do it.

~~~
pyre
Depends on what you're doing. In a small string, there isn't much difference.
It's more useful when doing other things:

    
    
      my $message = <<"HEREDOC";
      Greetings @{[ get_planet() ]}lings,
    
      We come in peace.
      
      Sincerely,
      Your New @{[ get_invaders() ]} Overlords
      HEREDOC
    

Sure you can jam them into variables first, or use sprintf, but it's a matter
of preference so long as you know what you're doing.

~~~
btilly
You can also use
[http://search.cpan.org/dist/Interpolation/lib/Interpolation....](http://search.cpan.org/dist/Interpolation/lib/Interpolation.pm)
for this problem. But if you've got a lot of text, I prefer to bite the bullet
and graduate to a proper templating system.

However my point still stands. You need to be aware that it does not simply
interpolate the function output in, it also switches you from scalar to list
context. (IMO context is the worst idea in Perl, but it is here to stay so you
need to know about it.)

------
JadeNB
Peteris Krumins wrote about some of these operators some years ago:
<http://www.catonmat.net/blog/secret-perl-operators>.

------
nemo1618
As someone who loves obfuscated Perl...thanks! These are some great tricks.

~~~
hippich
From someone who loves Perl, please do not use it in production :)

Although, it is really interesting find!

~~~
prakashk
While I generally agree that the discretion must be observed when working on
production code, I don't think the author is advocating these to be of wide
use.

These are very useful when you play Perl Golf, and can be pretty powerful in
the hands of an expert player (sadly, my dreams of becoming one has remained
just that.)

The author of this document was a regular in Perl Golf tournaments and also in
the Fun With Perl mailing list, which was a precursor and launchpad for
several of these tournaments.

For those interested, here is a series of articles about "The Lighter Side of
Perl Culture": <http://www.perlmonks.org/?node_id=410774>

See also, "Perlgolf History" at <http://terje2.frox25.no-
ip.org/perlgolf_history_070109.pdf> (not sure if this link is still alive.)

~~~
kamaal
Whoa!!!!, thanks for that pdf. Who ever compiled it has just done an awesome
job!

~~~
prakashk
If I remember correctly, that would be "mtve" [1] (who sometimes went by a
slightly longer "mtveurope"). If I had to pick the top three all-time Perl
golfers, he would be one of them.

[1] <http://www.perlmonks.com/index.pl?node_id=143426>

------
snorkel
Part of the reason I've stopped writing Perl apps, the operator noise is
getting out of hand.

~~~
hahainternet
Could you give examples? All of the recent Perl improvements have introduced
operators that seem extremely useful to me and _reduce_ noise.

