Book Home Programming PerlSearch this book

3.8. Additive Operators

Strangely enough, Perl also has the customary + (addition) and - (subtraction) operators. Both operators convert their arguments from strings to numeric values if necessary and return a numeric result.

Additionally, Perl provides the . operator, which does string concatenation. For example:

$almost = "Fred" . "Flintstone";    # returns FredFlintstone
Note that Perl does not place a space between the strings being concatenated. If you want the space, or if you have more than two strings to concatenate, you can use the join operator, described in Chapter 29, "Functions". Most often, though, people do their concatenation implicitly inside a double-quoted string:
$fullname = "$firstname $lastname";



Library Navigation Links

Copyright © 2001 O'Reilly & Associates. All rights reserved.