I have a requirement, where request_id will be in the form of
REQ0000001,REQ0000002....REQ0000010, REQ0000011...., REQ0000099 REQ0000100..... like first three char is REQ followed by 7 characters (number is sequence)… this request_id is the primary key in mysql table.
suppose last entry in table is REQ0000009, next entry wil be REQ0000010.. How to do it in perl??
I am using the following way:
$sql_query = "select request_id from requests order by request_id DESC LIMIT 1";
store this value in varibale named x. then
$x = reverse $x; #Reverse the String
chop $x; # Chop the last Character (here R)
chop $x; # Chop the last Character (here E)
chop $x; # Chop the last Character (here Q)
$x = reverse $x; # Again Reverse
$x = $x + 1; # Add 1
if ( length($x) eq 1) # if length ==1{
$NextReq_id = 'REQ000000'.$x;
elsif ( length($x) eq 2)
$NextReq_id = 'REQ00000'.$x;
elsif ( length($x) eq 3)
$NextReq_id = 'REQ0000'.$x;
elsif ( length($x) eq 4)
{
$NextReq_id = 'REQ000'.$x;
}
Is here any better way to do this?
1 Answer