Scalar Data
Summary
- Scalar variables and values.
- Operators - for numbers and strings.
- Communication between program and user (program input /
output).
- The chop and chomp functions.
Example program, to calculate average of two numbers entered by the user
(average.pl):
#!/usr/local/bin/perl
#receive user input (two numbers)
print "Type first number: ";
$first_no = <STDIN>;
chomp ($first_no);
print "Type second number: ";
$second_no = <STDIN>;
chomp ($second_no);
#calculate average
$average = ($first_no + $second_no) / 2;
#program output
print "Average is: $average\n";
Table of Contents.