Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

alphanumeric counter - howto?

 
 
Dr.Ruud
Guest
Posts: n/a
 
      11-15-2005
John W. Krahn:

> $ perl -MPOSIX -le'print strtoul "ZZ", 36'
> 12950


Nice. But it acts weirdly on bad input:

$ perl -MPOSIX -le 'print strtoul "ZZ _", 36'
129514

$ perl -MPOSIX -le 'print strtoul "ZZ_________", 36'
12959

--
Affijn, Ruud

"Gewoon is een tijger."
 
Reply With Quote
 
 
 
 
John W. Krahn
Guest
Posts: n/a
 
      11-15-2005
Dr.Ruud wrote:
> John W. Krahn:
>
>>$ perl -MPOSIX -le'print strtoul "ZZ", 36'
>>12950

>
> Nice. But it acts weirdly on bad input:
>
> $ perl -MPOSIX -le 'print strtoul "ZZ _", 36'
> 129514
>
> $ perl -MPOSIX -le 'print strtoul "ZZ_________", 36'
> 12959


As the documentation explains, strtol and strtoul return two values.

$ perl -MPOSIX -le 'print for strtoul "ZZ _", 36'
1295
14


John
--
use Perl;
program
fulfillment
 
Reply With Quote
 
 
 
 
Dr.Ruud
Guest
Posts: n/a
 
      11-15-2005
John W. Krahn:
> Dr.Ruud:
>> John W. Krahn:


>>> $ perl -MPOSIX -le'print strtoul "ZZ", 36'
>>> 12950

>>
>> Nice. But it acts weirdly on bad input:
>>
>> $ perl -MPOSIX -le 'print strtoul "ZZ _", 36'
>> 129514
>>
>> $ perl -MPOSIX -le 'print strtoul "ZZ_________", 36'
>> 12959

>
> As the documentation explains, strtol and strtoul return two values.
>
> $ perl -MPOSIX -le 'print for strtoul "ZZ _", 36'
> 1295
> 14


Aargh, I totally missed the order of magnitude from base36('ZZ') to
base10(12950).
For the next time: 36x36 is about 1000, not 10000.


It's a pity though that (yes, as the documentation says) it doesn't work
AIWLI beyond base 36:

$ perl -MPOSIX -le 'print scalar strtoul("ZZ", 62)'
2205

$ perl -MPOSIX -le 'print scalar strtoul("ZZ", 63)'
2240

$ perl -MPOSIX -le 'print scalar strtoul("zz", 62)'
2205

$ perl -MPOSIX -le 'print scalar strtoul("zz", 63)'
2240

--
Affijn, Ruud

"Gewoon is een tijger."

 
Reply With Quote
 
Brad Baxter
Guest
Posts: n/a
 
      11-15-2005
Dr.Ruud wrote:
> John W. Krahn:
>
> > $ perl -MPOSIX -le'print strtoul "ZZ", 36'
> > 12950

>
> Nice. But it acts weirdly on bad input:
>
> $ perl -MPOSIX -le 'print strtoul "ZZ _", 36'
> 129514
>
> $ perl -MPOSIX -le 'print strtoul "ZZ_________", 36'
> 12959


Not weird according to the docs. The second value
returned is the number of unparsed characters.

perl -MPOSIX -le'print join "\n", strtoul "ZZ", 36'
1295
0

FWIW, strtol ends at base 36. My interest in this
thread is that for some time I've used base 62 in a
bitvector database index compression/storage
scheme. It started as an experiment, but ended up
working rather nicely. I haven't hit the 2 billion record
mark, so overflow isn't yet an issue I've worried about.

--
Brad

 
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
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57