Translation rule
I like to create a translation rule to a VoIP system to o开发者_JS百科btain the following result: If someone dials the 4545 the system must convert this to 1234545, I managed to do this with the following rule: s/^4545/1234545/
My problem now is if someone dials 454567 my rule will convert this to 123454567 and I want to get 1234545 thx
Not clear on why should 454567 become 1234545? Should a string with a run of 4545 anywhere in it be come 1234545?
If you just want to change the exact string 4545 to 1234545 then you can use s/^4545$/1234545/
.
If you want a string with a run of 4545 anywhere in it to become 1234545 then you can use s/.*4545.*/1234545
.
$number='1234545' if ($number eq '4545'); #eq because phone number can contain non-digits.
If you want to convert any number that starts with '4545', use this code:
s/^4545.*/1234545/
精彩评论