Robin Sheat wrote:
On Sunday 12 March 2006 18:22, Shawn Corey wrote:
Believe it or not, write the number as a string.
for ( '000' .. '100' ){
   print "$_\n";
}
Note that if you have a string such as "000", you can treat it like a number:
my $a = '000';
$a++;
print "$a\n";

This will print '001'.

To have it go to 4 digits, well, that's as easy as you might expect:
my $a = '999';
$a++;
print "$a\n";

This will print '1000'.


This trick also works on letters:

#!/usr/bin/perl

use strict;
use warnings;

for ( 'a0' .. 'z9' ){
  print "$_\n";
}

__END__

See `perldoc perlop` and search for "Auto-increment and Auto-decrement"


--

Just my 0.00000002 million dollars worth,
   --- Shawn

"Probability is now one. Any problems that are left are your own."
  SS Heart of Gold, _The Hitchhiker's Guide to the Galaxy_

"This statement is true but unprovable."
  Kurt Godel

* Perl tutorials at http://perlmonks.org/?node=Tutorials
* A searchable perldoc is at http://perldoc.perl.org/


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to