[Courses] [Perl] Part 2: Scalar Variables

Fazia Begum Rizvi fazia at faziarizvi.net
Wed Apr 13 06:36:32 EST 2005


On Sat, 9 Apr 2005, Karine Delvare wrote:

> Hello Dan, thanks for the Perl course!
>
> Below is my homework, please tell me if I'm sending this too early.
>
>> 5) Exercises
>>
>> a) Write a program called 'average.pl' to calculate the average of
>> the following numbers: 23, 28, 31, 17, 1
>
> #!/usr/bin/perl -w
>
> use strict;
>
> my $num1 = 23;
> my $num2 = 28;
> my $num3 = 31;
> my $num4 = 17;
> my $num5 = 1;
>
> my $total = $num1 + $num2 + $num3 + $num4 + $num5;
>
> my $average = $total / 5;
>
> print "Average: $average\n";

Nifty. I eneded up doing this:


#!/bin/perl -w
# Perl Course Program
# Part 2: Scalar Variables
# Exercise "a" : Write a program called 'average.pl' to calculate the average of
# the following numbers: 23, 28, 31, 17, 1

use strict;
my $sum;
$sum = 23 + 28 + 31 + 17 + 1;
my $average;
$average = $sum / 5;

print "The average of 23, 28, 31, 17 and 1 is $average\n";



ad astra,
Faz

   (    Fazia Begum Rizvi
    )   www.faziarizvi.net
  ___
  \_/o


More information about the Courses mailing list