Expressions and Operators

Now that you've learned what scalar data is and know how to use scalar variables, you can start doing something useful with Perl. Perl programs are just collections of expressions and statements executed in order from the top of your Perl program to the bottom (unless you specify otherwise with flow-control statements, covered in Hour 3, “Controlling the Program's Flow”). Listing 2.1 shows a valid Perl program.

Listing 2.1. A Simple Perl Program
1:   #!/usr/bin/perl -w
3:   $radius=50;
5:   $area=3.14159*($radius ** 2);
6:   print $area;

Line 1: This line is the path to the Perl interpreter, as explained in Hour 1. The -w switch tells Perl to inform you of any warnings encountered.

Line 3: This line is an assignment ...

Get SAMS Teach Yourself Perl in 24 Hours THIRD EDITION 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.