Manual

- Overview
- Tutorials
- FAQs
- History / Changes
- License

Reference

- Language
- Functions
- Operators
- Special Variables
- Pragmas
- Utilities
- Internals
- Platform Specific

Modules

- A • B • C • D • E
- F • G • H • I • L
- M • N • O • P • S
- T • U • X

News / Blogs

- Perl Buzz
- Perl Iron Man
- Perlsphere
- Planet Perl
- TPF news
- Use Perl

See also

- CPAN
- Perl.org
- Perl.com
- Perl 5 Wiki
- Perl Jobs
- Perl Mongers
- Perl Monks

Contact

- Site designed and maintained by Jon Allen (JJ)
- http://perl.jonallen.info

- View the project page and FAQs

# scalar

Perl 5 version 10.1 documentation
Go to top

# scalar

Perl functions A-Z | Perl functions by category | The 'perlfunc' manpage

- scalar EXPR

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

          @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.

  Because `scalar` is unary operator, if you accidentally use for EXPR a parenthesized list, 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.

  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.

Recently read

Tools

- Preferences