Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > alphanumeric counter - howto?

Reply
Thread Tools

alphanumeric counter - howto?

 
 
Oliver Bleckmann
Guest
Posts: n/a
 
      11-11-2005
Hi,
I need an alphanumeric counter, which counts from 000000 to ZZZZZZ.
Is there an easy way to do this?

Thanks.

PS: Can perl calculate with alphanumeric numbers?



 
Reply With Quote
 
 
 
 
Brian Wakem
Guest
Posts: n/a
 
      11-11-2005
Oliver Bleckmann wrote:

> Hi,
> I need an alphanumeric counter, which counts from 000000 to ZZZZZZ.
> Is there an easy way to do this?
>
> Thanks.
>
> PS: Can perl calculate with alphanumeric numbers?



Does this help?
http://search.cpan.org/~rhenssel/Mat...0.02/Base36.pm


--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      11-11-2005
Oliver Bleckmann wrote:
> Hi,
> I need an alphanumeric counter, which counts from 000000 to ZZZZZZ.
> Is there an easy way to do this?


I found this module on CPAN:
http://search.cpan.org/src/RHENSSEL/...0.02/Base36.pm

However, it seems to have a very odd bug, in that it strips off the
first 'digit' from the encoded string. If you view the source, and
change decode_base36's last line from:
return(substr($t,1));
to:
return $t;

The module seems to start working correctly (it still fails its fifth
and final test, but I haven't analyzed why yet. After that change, the
following program should do what you want:

#!/usr/bin/perl
use strict;
use warnings;
use Math::Base36 qw/:all/;

for my $i (0..decode_base36('ZZZZZZ')){
print encode_base36($i), "\n";
}

__END__

(After further analysis, I will be attempting to contact the author and
submit a patch for this module...)

 
Reply With Quote
 
Brian Wakem
Guest
Posts: n/a
 
      11-11-2005
Paul Lalli wrote:

> Oliver Bleckmann wrote:
>> Hi,
>> I need an alphanumeric counter, which counts from 000000 to ZZZZZZ.
>> Is there an easy way to do this?

>
> I found this module on CPAN:
> http://search.cpan.org/src/RHENSSEL/...0.02/Base36.pm
>
> However, it seems to have a very odd bug, in that it strips off the
> first 'digit' from the encoded string. If you view the source, and
> change decode_base36's last line from:
> return(substr($t,1));
> to:
> return $t;



Quite bizarre. You've got to think he did that for a reason, you can't
accidentally type (substr($t,1)) instead if $t, but as you say, it appears
to be a bug.



--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      11-11-2005
Brian Wakem wrote:
> Paul Lalli wrote:
>
> > I found this module on CPAN:
> > http://search.cpan.org/src/RHENSSEL/...0.02/Base36.pm
> >
> > However, it seems to have a very odd bug, in that it strips off the
> > first 'digit' from the encoded string. If you view the source, and
> > change decode_base36's last line from:
> > return(substr($t,1));
> > to:
> > return $t;

>
>
> Quite bizarre. You've got to think he did that for a reason, you can't
> accidentally type (substr($t,1)) instead if $t, but as you say, it appears
> to be a bug.
>


Agreed. I wish the author had included more comments in the code to
explain his/her line of thought. What confuses me more, however is
this: http://testers.cpan.org/show/Math-Ba...th-Base36-0.02
Very few of the testers actually recorded failures. Now, when I
installed the package, although `make test` did show "not ok" for
tests 3-5, this did not hault the installation process (I don't
understand enough about the inner workings of CPAN.pm or the Test
suites to understand why). I wonder if the testers simply saw the end
result that the module installed, without noticing that 3 of the 5
tests failed.

Paul Lalli

 
Reply With Quote
 
jl_post@hotmail.com
Guest
Posts: n/a
 
      11-11-2005
> Oliver Bleckmann wrote:
> >
> > I need an alphanumeric counter, which counts from 000000 to ZZZZZZ.
> > Is there an easy way to do this?


Paul Lalli replied:
>
> I found this module on CPAN:
> http://search.cpan.org/src/RHENSSEL/...0.02/Base36.pm
>
> However, it seems to have a very odd bug, in that it strips off the
> first 'digit' from the encoded string.



Maybe I'm missing something obvious here, but when I look in the
code, I see the line:

my $_digits = '0123456789ABCDEFGHIJKLMNOPQRSTUVWZYX';

Is there any reason why the letters 'X' and 'Z' are swapped? The way
the letters are arranged now would make YYYYYY and XXXXXX bigger than
ZZZZZZ, which is not what the original poster wanted.

-- Jean-Luc

 
Reply With Quote
 
Brian McCauley
Guest
Posts: n/a
 
      11-11-2005
Oliver Bleckmann wrote:

> I need an alphanumeric counter, which counts from 000000 to ZZZZZZ.
> Is there an easy way to do this?


There is no built-in way to get a base 36 counter. Perl's builtin
string counter mechanism will count from 000000 to 999999 or from
AAAAAA to ZZZZZZ. (i.e. base 10 or 26).

> PS: Can perl calculate with alphanumeric numbers?


You mean numbers in base 36?

Numbers are conceptually just numbers (or if you prefer numbers base
2). It's only when you come to convert them to/from strings that they
can be said have some other base (typically 8,10 or 16).

AFAIK there's no built-in way for perl to convert a number to string
representation in base 2,8,10 or 16.

Perhaps you should look on CPAN for modules with "Base36" in their name.

 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      11-11-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Paul Lalli replied:
> >
> > I found this module on CPAN:
> > http://search.cpan.org/src/RHENSSEL/...0.02/Base36.pm
> >
> > However, it seems to have a very odd bug, in that it strips off the
> > first 'digit' from the encoded string.

>
>
> Maybe I'm missing something obvious here, but when I look in the
> code, I see the line:
>
> my $_digits = '0123456789ABCDEFGHIJKLMNOPQRSTUVWZYX';
>
> Is there any reason why the letters 'X' and 'Z' are swapped? The way
> the letters are arranged now would make YYYYYY and XXXXXX bigger than
> ZZZZZZ, which is not what the original poster wanted.


I have no idea why they're swapped either, but this oddness does not
affect the functionality of the module. the $_digits string is used
soley to determine whether or not the characters in the to-be-encoded
string are valid base-36 digits. The ordering is irrelevant. The
actual values of the base-36 digits are computed by subtracting 55 from
the ordinal value of the character in question.

Paul Lalli

 
Reply With Quote
 
Chris Johnson
Guest
Posts: n/a
 
      11-11-2005

Brian McCauley wrote:
> Oliver Bleckmann wrote:
>
> > I need an alphanumeric counter, which counts from 000000 to ZZZZZZ.
> > Is there an easy way to do this?

>
> There is no built-in way to get a base 36 counter. Perl's builtin
> string counter mechanism will count from 000000 to 999999 or from
> AAAAAA to ZZZZZZ. (i.e. base 10 or 26).
>
> > PS: Can perl calculate with alphanumeric numbers?

>
> You mean numbers in base 36?
>
> Numbers are conceptually just numbers (or if you prefer numbers base
> 2). It's only when you come to convert them to/from strings that they
> can be said have some other base (typically 8,10 or 16).
>
> AFAIK there's no built-in way for perl to convert a number to string
> representation in base 2,


sprintf("%b",$_)

> 8,


sprintf("%o",$_)

> 10,


sprintf("%d",$_) # $_ + 0 would do the same thing.

> or 16


sprintf("%x",$_)

> Perhaps you should look on CPAN for modules with "Base36" in their name.


 
Reply With Quote
 
Brian McCauley
Guest
Posts: n/a
 
      11-11-2005

Brian McCauley wrote:

> AFAIK there's no built-in way for perl to convert a number to string
> representation in base 2,8,10 or 16.


That should, of course, read "...other than in base...".

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Page File counter and Private Bytes Counter George2 C++ 1 01-31-2008 09:27 AM
Session("counter") vs. ViewState("counter")...a newbie question The Eeediot ASP .Net 3 12-22-2004 09:31 PM
Check if var is alphanumeric? VB Programmer ASP .Net 2 11-16-2004 06:46 PM
Natural sorting order for alphanumeric fields Paul Java 1 09-14-2004 12:41 PM
Easy way to specify all non-alphanumeric characters? Steven J Sobol Java 8 04-30-2004 09:15 AM



Advertisments