Questions And Answers

More Tutorials


Scalars are simple variables that are either numbers or strings of characters. Scalar variable names begin with a dollar sign followed by a letter, then possibly more letters, digits, or underscores. Variable names are case-sensitive.

Numbers are represented internally as either signed integers or double precision floating point numbers. Floating point literals are the same used in C. Integer literals include decimal (255), octal (0377), and hexadecimal (0xff) values.

Strings are simply sequences of characters. String literals are delimited by quotes:

Single quote‘stringEnclose a sequence of characters
Double quote“string”Subject to backslash and variable interpolation
Back quote`command`Evaluates to the output of the enclosed command

The backslash escapes are the same as those used in C:
\n Newline\e Escape
\r Carriage return\\ Backslash
\t Tab\” Double quote
\b Backspace\’ Single quote

In Windows, to represent a path, use either “c:\\temp” (an escaped backslash) or “c:/temp” (UNIX-style forward slash).
Strings can be concatenated using the “.” operator:
$foo = “hello” . ”world”;

Basic I/O
The easiest means to get operator input to your program is using the “diamond” operator:
$input = <>;

The input from the diamond operator includes a newline (\n). To get rid of this pesky character, use either chop() or chomp(). chop() removes the last character of the string, while chomp() removes any line-ending characters (defined in the special variable $/). If no argument is given, these functions operate on the $_ variable.
To do the converse, simply use Perl’s print function:
print $output.”\n”;


In this page (written and validated by ) you learned about Perl Scalars . What's Next? If you are interested in completing Perl tutorial, your next topic will be learning about: Perl Basic Operators.

Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue:

Share On:

Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using, you agree to have read and accepted our terms of use, cookies and privacy policy.