Note that a simple way to force scalar context on anything is scalar, as in print scalar <STDIN>;.
| [reply] [d/l] |
Also note that while there is no similar keyword for forcing list context, it can be done with @{[]}, as in print @{[<STDIN>]}, but actually using that is an advanced feature and if you force list context in a scalar context, you will get the number of items in the list rather than any of the values in list.
| [reply] [d/l] [select] |
if you force list context in a scalar context, you will get the number of items in the list rather than any of the values in list
For the @{[...]} form you showed, that's correct, because it's an array, not a list - but more generally, the usual behavior of lists and arrays in scalar context applies. As documented in scalar:
There is no equivalent operator to force an expression to be interpolated in list context because in practice, this is never needed. If you really wanted to do so, however, you could use the construction @{[ (some expression) ]}, but usually a simple (some expression) suffices.
Because scalar is a unary operator, if you accidentally use a parenthesized list for the EXPR, this behaves as a scalar comma expression, evaluating all but the last element in void context and returning the final element evaluated in scalar context. This is seldom what you want.
| [reply] [d/l] [select] |