#!/usr/bin/perl use strict; ################################################## #file: #This program takes in 4 numbers and calculates the sum using two methods #To use it, at the command line type perl numbers.pl number_1 number_2 number_3 number_4 #date: # #Author: ################################################## #declare variables my $num1; my $num2; my $num3; my $num4; my $total1; my $total2; my $i; my $count; my @numbers; my %animals; #check number of arguments if($#ARGV != 3) { print "perl numbers.pl num1 num2 num3 num4\n"; exit(0); } #read in numbers; $num1=$ARGV[0]; $num2=$ARGV[1]; $num3=$ARGV[2]; $num4=$ARGV[3]; #calculate sum of inputs $total1=$num1+$num2+$num3+$num4; print "\nUsing scalars, the sum is $total1\n\n"; #construct an array from the command line for($i=0;$i<@ARGV;$i++) { push @numbers, $ARGV[$i]; $count++; print "The loop has executed $count times.\n"; print "The array" . ' @numbers ' . "now contains: @numbers\n\n"; } #doing calculation with elements in an array for($i=0;$i<@numbers;$i++) { $total2+=$numbers[$i]; } print "The sum using an array is $total2!!\n\n";