#!/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)); } } =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<range> ... =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<tac> or L<dog>. 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 nume +ric B<range> 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 <jpierce@cpan.org>. =end

--
I'm not belgian but I play one on TV.


In reply to range by belg4mit

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.