Variable Declarations and Simple Expressions

You start your exploration of Perl by looking at simple, single-value variables. Next you use these variables in some basic expressions. Almost all the concepts discussed here have equivalents in C, so learning them should not be too difficult.

Variables

Unlike most other languages, Perl doesn’t have different variable types. There is only one type of data in Perl: the string. Perl lets you use numbers, but as far as Perl is concerned what you really have is a string of digits. Want to deal with characters? Then you’re dealing with one-character strings. Want to handle binary? Then you’re dealing with a string of 1s and 0s.

To declare a variable in Perl, use the directive my:

 my $size = 42; # The ...

Get Perl for C Programmers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.