#! /usr/bin/perl # subro - illustrate code using subroutine to repeat # count number of digits in specified range # Note that combining a calculation and a print statement would nott # normally be good design, but for this example it will not matter # use strict; use warnings; count (1, 4); count (3, 7); # The actual work has been extracted into a subroutine # sub count { # arguments are first and last numbers in range my ($start, $end) = @_; # save argument array to scalars my $number; for ($start..$end) { $number++; } print "Number is $number\n"; return; } # End subro