#!/usr/local/bin/perl5 -w # $Id: range,v 1.3 2001/03/27 10:15:10 max Exp $ use strict; use Getopt::Long; my $start = undef; my $end = undef; my $stepsize = 1; my $prefix = undef; my $suffix = undef; my $zeropad = undef; my $strtmpl = "%s%d%s%s"; my $separator = " "; GetOptions("start=i" => \$start, "end=i" => \$end, "prefix=s" => \$prefix, "suffix=s" => \$suffix, "stepsize=i" => \$stepsize, "zeropad=i" => \$zeropad, "separator=s" => \$separator, "help" => \&showhelp); if ((defined $start) && (defined $end)) { # Everything is ok. User specified everything through option } elsif ((!defined $start) && (!defined $end) && (scalar @ARGV >= 2)) { # Use up to the first four things in ARGV as start, end, prefix and # suffix respectively. $start = $ARGV[0]; $end = $ARGV[1]; $prefix = $ARGV[2] if ((! defined $prefix) && (@ARGV >= 3)); $suffix = $ARGV[3] if ((! defined $suffix) && (@ARGV >= 4)); $zeropad = $ARGV[4] if ((! defined $zeropad) && (@ARGV >= 5)); } elsif ((!defined $start) && (!defined $end) && (scalar @ARGV == 0)) { print "Usage: range [options] \n"; exit; } else { print "You must specify both the start and the end of the range.\n"; exit; } $prefix = "" unless defined $prefix; $suffix = "" unless defined $suffix; if ((defined $zeropad) && ($zeropad < 0)) { print "You cannot have negative padding!\n"; exit; } if ((defined $stepsize) && ($stepsize <= 0)) { print "You cannot have a stepsize less than or equalt to zero!\n"; exit; } if ((defined $zeropad) && ($zeropad != 0)) { $strtmpl = "%s%0" . $zeropad . "d%s%s"; } my $i; if ($start <= $end) { for ($i = $start; $i <= $end; $i += $stepsize) { printf($strtmpl, $prefix, $i, $suffix, $separator); } } else { for ($i = $start; $i >= $end; $i -= $stepsize) { printf($strtmpl, $prefix, $i, $suffix, $separator); } } print "\n"; sub showhelp { print<