我有一个要求,其中request_id的形式是 REQ0000001,REQ0000002....REQ0000010, REQ0000011...., REQ0000099 REQ0000100.....
像前三个字符是REQ后跟7个字符(数字是序列)...此request_id是mysql中的主键表。如何生成下一个请求ID
假设表中的最后一项是REQ0000009,下一项将是REQ0000010 ..如何在perl中完成?
我使用方式如下:
$sql_query = "select request_id from requests order by request_id DESC LIMIT 1";
店varibale这个值命名为x。那么
$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;
}
这里有更好的方法吗?
你将如何处理'REQ9999999'? 'RER0000000'或'REQ10000000'? – TLP