#! 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;
In reply to Re: a simple exercise in readability
by BrowserUk
in thread a simple exercise in readability
by apotheon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |