Scalar Data

Summary


Example program, to calculate average of two numbers entered by the user (average.pl):

#!/usr/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.
Previous.