Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > autoincrement hex numbers

Reply
Thread Tools

autoincrement hex numbers

 
 
cartercc@gmail.com
Guest
Posts: n/a
 
      04-17-2006
Can Perl autoincrement hex numbers?

Our problem is that we have a field only four characters wide, and we
anticipate that we may have more than 10,000 records to uniquely
identify in this field. We need to autoincrement this field.

Many, many TIA, CC.

 
Reply With Quote
 
 
 
 
Nico Coetzee
Guest
Posts: n/a
 
      04-17-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Can Perl autoincrement hex numbers?
>
> Our problem is that we have a field only four characters wide, and we
> anticipate that we may have more than 10,000 records to uniquely
> identify in this field. We need to autoincrement this field.
>
> Many, many TIA, CC.
>


use Math::BaseCnv;
my $hex = $ARGV[0];
my $num = cnv( $hex, 16, 10 );
$num++;
$hex = cnv( $num, 10, 16 );
 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      04-17-2006
(E-Mail Removed) wrote:
> Can Perl autoincrement hex numbers?


Not inherently. Strictly speaking, there are no hex numbers, only hex
representations of numbers. You could probably make a module (or find
one on CPAN) that will alter make stringification automatically produce
hex representations, and numification automatically use hex
representations.

> Our problem is that we have a field only four characters wide, and we
> anticipate that we may have more than 10,000 records to uniquely
> identify in this field. We need to autoincrement this field.


Do you really need to autoincrement it? What is wrong with using some
something other than autoincrement, like, say hex_increment($thing)?

sub hex_increment {
$_[0] = sprintf "%x", 1+hex$_[0];
};

Or how about using base 26 rather than base 16? Then you could just use
the stringy autoincrement.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
Uri Guttman
Guest
Posts: n/a
 
      04-17-2006
>>>>> "NC" == Nico Coetzee <(E-Mail Removed)> writes:

NC> (E-Mail Removed) wrote:
>> Can Perl autoincrement hex numbers?
>> Our problem is that we have a field only four characters wide, and we
>> anticipate that we may have more than 10,000 records to uniquely
>> identify in this field. We need to autoincrement this field.
>> Many, many TIA, CC.
>>


NC> use Math::BaseCnv;
NC> my $hex = $ARGV[0];
NC> my $num = cnv( $hex, 16, 10 );
NC> $num++;
NC> $hex = cnv( $num, 10, 16 );

ever heard of the hex() and oct() functions in perl?

uri

--
Uri Guttman ------ (E-Mail Removed) -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      04-18-2006
(E-Mail Removed) <(E-Mail Removed)> wrote:

> Can Perl autoincrement hex numbers?



Pfft!

What's with that wimpy base-16 when base-26 is free for the taking?


perl -le '$a='a'; print $a++ for 1 .. 1000'


--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
cartercc@gmail.com
Guest
Posts: n/a
 
      04-18-2006
Many thanks for all the help.

I used Math::BaseCnv. The lines that do the work are as follows:

$counter = 0; #integral value
$key = sprintf("%04s", cnv(++$counter));

$counter gets saved in a text file to save the accumulated the values
between invocations, and $key gets written into rows for an upload
file.

CC

 
Reply With Quote
 
Nico Coetzee
Guest
Posts: n/a
 
      04-18-2006
Uri Guttman wrote:
>>>>>> "NC" == Nico Coetzee <(E-Mail Removed)> writes:

>
> NC> (E-Mail Removed) wrote:
> >> Can Perl autoincrement hex numbers?
> >> Our problem is that we have a field only four characters wide, and we
> >> anticipate that we may have more than 10,000 records to uniquely
> >> identify in this field. We need to autoincrement this field.
> >> Many, many TIA, CC.
> >>

>
> NC> use Math::BaseCnv;
> NC> my $hex = $ARGV[0];
> NC> my $num = cnv( $hex, 16, 10 );
> NC> $num++;
> NC> $hex = cnv( $num, 10, 16 );
>
> ever heard of the hex() and oct() functions in perl?
>
> uri
>


Never use it - this was a quick search on CPAN
 
Reply With Quote
 
Uri Guttman
Guest
Posts: n/a
 
      04-18-2006
>>>>> "NC" == Nico Coetzee <(E-Mail Removed)> writes:

NC> Uri Guttman wrote:
>>>>>>> "NC" == Nico Coetzee <(E-Mail Removed)> writes:

NC> (E-Mail Removed) wrote:
>> >> Can Perl autoincrement hex numbers?
>> >> Our problem is that we have a field only four characters wide, and we
>> >> anticipate that we may have more than 10,000 records to uniquely
>> >> identify in this field. We need to autoincrement this field.
>> >> Many, many TIA, CC.
>> >> NC> use Math::BaseCnv;

NC> my $hex = $ARGV[0];
NC> my $num = cnv( $hex, 16, 10 );
NC> $num++;
NC> $hex = cnv( $num, 10, 16 );
>> ever heard of the hex() and oct() functions in perl?
>> uri
>>


NC> Never use it - this was a quick search on CPAN

why would you search cpan before you even searched perl's docs? modules
are for the things that are not builtin to perl. hex and octal
conversion are core things perl does just fine without a module.

uri

--
Uri Guttman ------ (E-Mail Removed) -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
 
Reply With Quote
 
Nico Coetzee
Guest
Posts: n/a
 
      04-18-2006
Uri Guttman wrote:
>>>>>> "NC" == Nico Coetzee <(E-Mail Removed)> writes:

>
> NC> Uri Guttman wrote:
> >>>>>>> "NC" == Nico Coetzee <(E-Mail Removed)> writes:

> NC> (E-Mail Removed) wrote:
> >> >> Can Perl autoincrement hex numbers?
> >> >> Our problem is that we have a field only four characters wide, and we
> >> >> anticipate that we may have more than 10,000 records to uniquely
> >> >> identify in this field. We need to autoincrement this field.
> >> >> Many, many TIA, CC.
> >> >> NC> use Math::BaseCnv;

> NC> my $hex = $ARGV[0];
> NC> my $num = cnv( $hex, 16, 10 );
> NC> $num++;
> NC> $hex = cnv( $num, 10, 16 );
> >> ever heard of the hex() and oct() functions in perl?
> >> uri
> >>

>
> NC> Never use it - this was a quick search on CPAN
>
> why would you search cpan before you even searched perl's docs? modules
> are for the things that are not builtin to perl. hex and octal
> conversion are core things perl does just fine without a module.
>
> uri
>


Do you have a point? Or do you just want some acknowledgment?
 
Reply With Quote
 
Dr.Ruud
Guest
Posts: n/a
 
      04-18-2006
(E-Mail Removed) schreef:

> [Math::BaseCnv]
> $counter = 0; #integral value
> $key = sprintf("%04s", cnv(++$counter));


$key = sprintf '%04x', ++$counter;

See `perldoc -f sprintf`.

--
Affijn, Ruud

"Gewoon is een tijger."
 
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
Hex Color Codes - Hex 6 <=> Hex 3 lucanos@gmail.com HTML 10 08-18-2005 11:21 PM
autoincrement strangeness - please help! Munnki Perl 2 12-18-2003 10:51 PM
Getting the AutoIncrement column data RA ASP .Net 0 10-21-2003 09:52 PM
hex(-5) => Futurewarning: ugh, can't we have a better hex than '-'[:n<0]+hex(abs(n)) ?? Bengt Richter Python 6 08-19-2003 07:33 AM
Re: ViewState + AutoIncrement -- Okay; Session + AutoIncrement -- Not okay Gene Gorokhovsky ASP .Net 0 07-17-2003 02:48 PM



Advertisments