#!/usr/bin/perl -sw use strict; use vars qw($i $n $N $R $VERSION @F); $VERSION = 0.03; sub printN{ printf("%0$N.f\n", @_); } if( scalar @ARGV == 1 && $ARGV[0] !~ /,|-|\./ ){ if( $ARGV[0] =~ /^\d/ ){ $ARGV[0] = '0-'.$ARGV[0]; } else{ $ARGV[0] = 'a-'.$ARGV[0]; } } if( scalar @ARGV == 2 && $ARGV[0] !~ /,|-|\./ && $ARGV[1] !~ /,|-|\./ ){ $ARGV[0] .= '-'; } @F = split(',', join(',', @ARGV)); while( $R = shift(@F) ){ my($A, $B, $j) = (0,0,1); if( $R =~ /-|\./ ){ if( $R !~ /\w\)?$/ ){ $R .= shift(@F); } ($A, $B) = split(/-|(?:\.\.)/, $R); } else{ die("Invalid range\n") unless shift(@F) =~ /(?:-|(?:\.\.))(\w+)?/; $A = $R; $B = $1 ? $1 : shift(@F); } local $N = $A =~ /^0/ ? length($A) : $n || 0; # if( $B =~ s/\[(.+)\]$// ){ #Old style if( $B =~ s/\/(.+)$// ){ #Cron style $j = $1; } if( $A =~ /^\((\d+)\)$/ ){ $A = -$1; } if( $B =~ /^\((\d+)\)$/ ){ $B = -$1; } if( $j =~ /^\((\d+)\)$/ ){ $j = -$1; } #check for mismatched limits eg; a-9? #And mixedstr? a1-a9 (should not be done) a1-b9? if( $A =~ /\d/ ){ #specify interval?! (positive only) if( $A < $B ){ for($i=$A;$i<=$B;$i+=$j){ printN "$i"; } } if( $A > $B ){ for($i=$A;$i>=$B;$i-=$j){ printN "$i"; } } printN "$A" if $A == $B; } else{ #this doesn't allow for stepping, or intervals... #easy to do, but then supporting width>1 is not map(printf("%${N}s\n", $_), ($A..$B)); } } __END__ =pod =head1 NAME range - output a range of values; one per line =head1 SYNOPSIS range [B<-n=>pad] [ upperLimit | range | range,range... ] OR range lowerLimit upperLimit OR range F ... =head1 DESCRIPTION If only an upperLimit is set the lowerLimit is 0 or a as appropriate. Mutliple ranges may be supplied as individual arguments, or by delimiting them with a comma in the same argument. Negative numbers are specified by enclosing within parentheses; you will likely need to escape or quote such sequences to protect them from your shell. Only alphabetical ranges in ascending order are supported, to reverse an alphabetical range see L or L. Ranges may be defined with either the MH mail standard I<-> or the Perl standard I<..> Stepping may be performed on a numeric range with cron-like syntax by following the upperLimit I and a value. =head1 OPTIONS =over 4 =item B<-n=>pad Pad the resulting strings to the width specified. If the range is numeric B will pad output for a range with a zero-padded lowerLimit to the width of the lowerLimit. =back =head1 EXAMPLES range zz range 1..10 range 1-4,8-12 range 99 0 range 1-5,6 - 10 (7)..42 100 .. 18/3 =head1 BUGS .sgub nownk oN =head1 AUTHOR Jerrad Pierce . =end