Cari di Perl 
    Perl User Manual
Daftar Isi
(Sebelumnya) Clear all variables of a given nameRemove a variable or function ... (Berikutnya)
Miscellaneous functions

Force a scalar context

Daftar Isi

  • scalar EXPR

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

    1. @counts = ( scalar @a, scalar @b, scalar @c );

    There is no equivalent operator to force an expression tobe interpolated in list context because in practice, this is neverneeded. If you really wanted to do so, however, you could usethe construction @{[ (some expression) ]}, but usually a simple(some expression) suffices.

    Because scalar is a unary operator, if you accidentally use aparenthesized list for the EXPR, this behaves as a scalar comma expression,evaluating all but the last element in void context and returning the finalelement evaluated in scalar context. This is seldom what you want.

    The following single statement:

    1. print uc(scalar(&foo,$bar)),$baz;

    is the moral equivalent of these two:

    1. &foo;
    2. print(uc($bar),$baz);

    See perlop for more details on unary operators and the comma operator.

 
Source : perldoc.perl.org - Official documentation for the Perl programming language
Site maintained by Jon Allen (JJ)     See the project page for more details
Documentation maintained by the Perl 5 Porters
(Sebelumnya) Clear all variables of a given nameRemove a variable or function ... (Berikutnya)