Scalar Variables


Beginning | Previous | Next

Types of Scalars

A scalar can be an integer, floating point, a string or a reference to another variable/object, such as, $a = 2; # integer $b1 = 0.55; # floating point # $cheese is a reference to the array @munster $cheese = \@munster; Note: A pound sign, "#", is a comment character in Perl - everything to the end of the line is ignored by the interpreter.

Strings

A string is a type of scalar. They can be created by an assignment you write or from the return of a function, such as: $lizard = 'some string'; $bilge = "The amount of bilge we got is $var\n"; # &get_name() is a function call $name = &get_name();

The difference between single quotes, ' ', and double quotes, " ", for string variables is that the single quote take strings literally and double quotes will perform interpolation, that is, the value of $var, above, will be inserted into the string variable $bilge along with the code for a new line "\n". This is similar to how the UNIX shell works.

For example:

$var = 4; print 'var = $var', "\n"; print "var = $var\n"; produces the output: var = $var var = 4

String Literals

Code Meaning
\t
tab
\n
newline
\r
return
\f
form feed
\v
vertical tab, whatever that is
\b
backspace
\a
alarm (bell)
\e
escape
\033
octal char
\x1b
hex char
\c[
control char
\l
lowercase next char
\u
uppercase next char
\L
lowercase till \E
\U
uppercase till \E
\E
end case modification
\Q
quote regexp metacharacters till \E


Beginning | Previous | Next
Last Modified: $Date: 1997/05/02 07:17:49 $