Basic Concepts in Perl
Variables
$city = "Sunnyvale";
$morning_temperature = 12.5;
$evening_temperature = 16.6;
$average_T = ($morning_temperature+$evening_temperature)/2.0;
One dimensional list of scalars
@coins = (1,5,10,25);
print $coin[0];
@somecoins[0,1] = @coins[0,1];
operators for numbers
+ plus
 minus
* multiply
/ divide
** exponential
% modulus # e.g., 7 % 3 = 1
== equal
!= not equal
< less than
> greater than
<= less than or equal to
>= greater than or equal to
operators for strings
. concatenate (it is the dot character, example strings a.b will become ab)
x n repetition # e.g., "A" x 3 => "AAA"
eq equal (this is used for strings, compare with == for numeric)
ne not equal
lt less than
gt grater than
le less than or equal to
ge greater than or equal to
chomp() (remove last control character in string, very useful in string handling!)
conversion between numbers and strings
Automatic process determined by the operator, if reasonable
(e.g., "1.23" as string converts to 1.23 as number).
If unreasonable, string converts to zero (0) as number
(e.g., "not_a_number" converts to 0).
Go to perlpage 5 ... Back to perlpage 3 ... Starting page
