While I understand the @{[....]} and ${\....} constructs, I don't understand ${\~~....}.
Consider the following snippet:
use strict; use warnings; sub context { print wantarray ? "List\n" : "Scalar\n"; } my $string; $string = "Test @{[context()]} string"; $string = "Test ${\context()} string"; $string = "Test ${\~~context()} string"; __OUTPUT__ List List Scalar
I've seen the first two constructs before, but the third is a new one to me. How is ~~ forcing scalar context?
I've looked in perlop and find no mention of ~~. A single ~ is the bitwise negation operator. But I don't think that has anything to do with ~~. The only place I find mention of '~~' is under perlform, where it's mentioned as a "repeat the previous format character until the line is filled" format operator. But again that doesn't seem to make sense in the context of interpolating code into a string.
Of course all three of the above constructs are not terribly pretty, and should probably be avoided when it's convenient to do so. But that doesn't stop my wondering. If anyone can shed some light on what ~~ is doing, I'd love to hear.
Dave
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |