#!/usr/bin/perl -l use strict; use warnings; use Getopt::Std; our $VERSION = '1.0'; $Getopt::Std::STANDARD_HELP_VERSION = 'true'; my $help = ' syntax: series [-s] --help prints this help text and exits: invoking the help argument causes all other arguments to be discarded by this utility -s takes no arguments: changes program behavior so that the first number specified is the first number of the range, and not the number preceding it (syntax: series a+1 n) -- this option must precede all numerical arguments to the series utility description: This utility takes two positive integers as arguments and produces the sum of the range of integers starting after the first argument and ending with the second argument. It allows 0 to be specified as the first argument, indicating that all numbers in the range are positive integers. credits: Chad L. Perrin (author) PerlMonks community (contributors) -- node 594743 license: This software is licensed CCD CopyWrite. See the webpage at http://ccd.apotheon.org for licensing details. '; our ($opt_s); getopts('s'); die $help unless defined $ARGV[1]; map { /^-?\d+$/ or die "Invalid input: '$_'$!" } @ARGV; die "Error: arguments in descending value order.\n$help" if ($ARGV[0] > $ARGV[1]); my $start = $ARGV[0] + ( $opt_s ? 0 : 1); my $end = $ARGV[1]; print( ($end - $start + 1) * ($start + $end) / 2 ); sub HELP_MESSAGE { print $help }