Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Incrementing problem (I'm missing something here)

Status
Not open for further replies.

mstelmac

Technical User
Oct 22, 2003
53
0
0
US
hello everyone,

I have the following code that works flawlessly except doe not count higher that 10. When it reaches 10 it just keeps repeating 10. I am using the code to assign unique numbers and store them in a database field.

$sw_version = "3.1.1";
$asset_name = "ShipName";
$retreived_value = "3.1.1_ShipName_10";

my $incremented_value = (split(/\_/, $retreived_value))[-1];
$incremented_value ++;
$incremented_value = $sw_version."_".$asset_name."_".$incremented_value;

Thanks in advance for any help :)
 
What database are you storing in?

Try reading the vaule before and after you put it in the database.
 
Kevin197,

I'm using a SQL Server database and your exactly right (DOH). Has nothing to do with the perl script that increments the value....it's the SQL max command Im using.

When searching for strings the value "whatever_9" will always be the max to "whatever_10 or 11, or 12".

Dang.....now I gotta figure out how to select the max string :)

thanks,
Matt
 
This is because you use lexical sorting: [tt]10[/tt] precedes [tt]9[/tt] with lexical sorting.
You should format the appended numbers as [tt]09[/tt] (or [tt]009[/tt]..., depends on maximum value), or extract the appended number and sort numerically.

Franco
: Online tools for structural design
: Magnetic brakes for fun rides
: Air bearing pads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top