in reply to a simple exercise in readability
#! perl -slw use strict; our $h; our $s; die <<usage if $h or @ARGV != 2; $0 [-s] low high Calculates sum( low+1 .. high ) With -s calculates sum( low .. high ) (integers only) usage my( $low, $high ) = @ARGV; die "Arguments must be integers\n" unless $low =~ m[^\d+$] and $high =~ m[^\d+$]; my $result = ( $low + $high ) * ( $high - $low + 1 ) / 2; $result -= $low unless $s; print $result;
|
|---|