eWebProgrammer eweb  

Basic Perl  «Prev  Next»
Lesson 1

Perl operators

Perl Operator Source
This module will prepare you to operate on the Perl variables that you learned about in the previous module. With a good understanding of the operations available in the language, you will be able to choose the best operator for a given situation or requirement.
To be able to effectively write programs that work exactly how you want them to, you need to have a good grasp of what facilities a language offers, and how to use them. The Perl language has a rich selection of operators, and if you take the time to understand them you will be rewarded every time you write a Perl program.

A variable is just a place to store a value, so you can refer to it or manipulate it throughout your program. Perl has three types of variables:
  1. scalars,
  2. arrays, and
  3. hashes.

A scalar variable stores a single (scalar) value. Perl scalar names are prefixed with a dollar sign ($), so for example, $x, $y, $z, and $url are all examples of scalar variable names. Here's how variables are used:
$num = 1;
$name = "Tom";
$pi = 3.1415927;
You do not need to declare a variable before using it.
A scalar can hold data of any type, be it a string or number.
You can also drop scalars into double-quoted strings:
$prime = 23;
$text = "The magic number is $prime.";
Now if you print $text, you will get "The magic number is 23." Let's edit first.pl again and add some scalars to it:
$classname = "Basic Perl Programming";
print "Hello there.  What is your name?\n";
$you = ;
print "Hello, $you.  Welcome to $classname.\n";