#!/usr/bin/perl -l # Libraries use strict; use warnings; use Getopt::Std; use File::Basename; our ($opt_s); getopts('s'); # Globals my $iam = basename $0; my $syntax = " syntax: $iam Your syntax message here. "; # Command-line (my $x = shift) or die $syntax; (my $y = shift) or die $syntax; # Validity checking ($x =~ /^-?\d+$/) or die "$iam: value $x not an integer\n"; ($y =~ /^-?\d+$/) or die "$iam: value $y not an integer\n"; # Main program if ($opt_s) { printf "%d\n", ($y - $x + 1) * ($x + $y) / 2; } else { printf "%d\n", ($y - $x) * ($x + $y + 1) / 2; }