in reply to Re: Re: How does ~~ force string interpolation of code into scalar context?
in thread How does ~~ force string interpolation of code into scalar context?

I found that the following will also at least compile and force scalar context. Some of them will mangle return values though. ;)

Actually, of the four additional combinations you tried, only -+- would be at all useful. It avoids mangling integers and floats. The three others mangle everything.¹ Also, with 5.6.1 and 5.8.0 at least, using this will cause warnings about ambiguity unless warnings are explicitly disabled.

Still, it may have some golf merit in being a short way to impose scalar context on functions that return floating point numbers. For strings or ints, though, I think ~~ is still preferable. For golf or obfuscation that is. Of course, scalar() is far better for "real" code.

By the way, -+- might also be written as - -, the plus or space only being necessary to differentiate it from a decrement.

1. In fact, &\& will, I think, always fail under strict checking.

-sauoq
"My two cents aren't worth a dime.";
  • Comment on Re: Re: Re: How does ~~ force string interpolation of code into scalar context?