perl-5.38.0
scalar EXPR

Forces EXPR to be interpreted in scalar context and returns the value of EXPR.

EXPR を強制的にスカラコンテキストで解釈されるようにして、 EXPR の値を返します。

    my @counts = ( scalar @a, scalar @b, scalar @c );

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.

式を強制的にリストコンテキストで解釈させるようにする演算子はありません; 理論的には不要だからです。 それでも、もしそうしたいのなら、@{[ (some expression) ]} という構造を 使えます; しかし、普通は単に (some expression) とすれば十分です。

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.

scalar は単項演算子なので、EXPR として括弧でくくった リストを使った場合、これはスカラカンマ表現として振舞い、最後以外の全ては 無効コンテキストとして扱われ、最後の要素をスカラコンテキストとして扱った 結果が返されます。 これがあなたの望むものであることはめったにないでしょう。

The following single statement:

以下の一つの文は:

    print uc(scalar(foo(), $bar)), $baz;

is the moral equivalent of these two:

以下の二つの文と等価です。

    foo();
    print(uc($bar), $baz);

See perlop for more details on unary operators and the comma operator, and perldata for details on evaluating a hash in scalar context.

単項演算子とカンマ演算子に関する詳細については perlop を、 スカラコンテキストでのハッシュの評価に関する詳細については perldata を 参照してください。