Perlsecret - Perl secret operators and constants
search.cpan.org
Perlsecret - Perl secret operators and constants
1–10 of 19 posts
Re: Perlsecret - Perl secret operators and constants
#2 "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.Re: Perlsecret - Perl secret operators and constants
#3Re: Perlsecret - Perl secret operators and constants
#4This 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.
"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.Re: Perlsecret - Perl secret operators and constants
#5This 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.
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.
my $message =
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.Re: Perlsecret - Perl secret operators and constants
#6As someone who loves obfuscated Perl...thanks! These are some great tricks.
Although, it is really interesting find!
Re: Perlsecret - Perl secret operators and constants
#7Earlier quoted context omitted.
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.
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 = 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.
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.)
Re: Perlsecret - Perl secret operators and constants
#8This 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.
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.
"Greetings ${\ get_planet() }lings, we come in peace!"
will give you scalar context as well. My http://shadow.cat/blog/matt-s-trout/madness-with-methods write-up covers some other uses of ${\}Re: Perlsecret - Perl secret operators and constants
#9Re: Perlsecret - Perl secret operators and constants
#10Part of the reason I've stopped writing Perl apps, the operator noise is getting out of hand.