Article View: comp.sources.d
Article #4997Re: v06i100: Count program - leading zero enhancement
From: Bernie Cosell
Date: Tue, 16 May 1989 21:15
Date: Tue, 16 May 1989 21:15
56 lines
1760 bytes
1760 bytes
In article <33795@mongo.uucp> waynet@mongo.uucp (Wayne Thompson) writes:
}Here's a short script that does the same.
I hate to be picky, but the script has a bit of a problem. Try feeding it
count 5 -w6 7
or
count 5 xxy
On the other hand, here's a short perl script that also does the job.
It is a bit longer than the shell script, but a fair amount of that is doing
error checking and such.
__
/ ) Bernie Cosell
/--< _ __ __ o _ BBN Sys & Tech, Cambridge, MA 02238
/___/_(<_/ (_/) )_(_(<_ cosell@bbn.com
#!/usr/local/bin/perl
# Output a sequence of integers
$Usage="usage: num [-wWIDTH] [firstn] lastn\n";
sub Usage { printf stderr $Usage ; exit 1; }
do Usage() if ($#ARGV < 0 || $#ARGV > 2);
$lastnum = pop(@ARGV);
do Usage() if $lastnum !~ /^[0-9]*$/;
if ($#ARGV >= 0 && $ARGV[0] =~ /^-w([0-9]*)$/)
{
$width = $1;
shift(@ARGV);
}
else
{
$width = length($lastnum);
}
if ($#ARGV >= 0)
{
$firstnum = $ARGV[0];
do Usage() if $firstnum !~ /^[0-9]*$/ || $#ARGV != 0;
}
else
{
$firstnum = 1;
}
for ($i = $firstnum; $i <= $lastnum; $i += 1)
{
printf ("%0${width}d\n", $i);
}
exit 0;
Technical Details
Message-ID:
<40035@bbn.COM>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!cs.utexas.edu!tut.cis.ohio-state.edu!unmvax!gatech!bbn!bbn.com!cosellReferences:
<54804@uunet.UU.NET> <1989May16.000313.8145@tmsoft.uucp> <33795@mongo.uucp>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!cs.utexas.edu!tut.cis.ohio-state.edu!unmvax!gatech!bbn!bbn.com!cosell From: cosell@bbn.com (Bernie Cosell) Newsgroups: comp.sources.d Subject: Re: v06i100: Count program - leading zero enhancement Message-ID: <40035@bbn.COM> Date: 16 May 89 21:15:05 GMT References: <54804@uunet.UU.NET> <1989May16.000313.8145@tmsoft.uucp> <33795@mongo.uucp> Sender: news@bbn.COM Reply-To: cosell@BBN.COM (Bernie Cosell) Organization: Bolt Beranek and Newman Inc., Cambridge MA Lines: 56