in reply to Add 1 to an arbitrary-length binary string
This increments the Unicode code-point rather than its utf8 encoding that your integer arithmetic would increment. In the cases where it makes a difference, I suspect that this is what the author of your document had in mind. This will fail if your strings are restricted to ASCII Characters and the last character of the string is an ASCII DEL (U+7F).use strict; use warnings; my $str = 'arbitrary length string.xxx'; substr($str, -1, 1) = chr(ord(substr($str, -1, 1))+1); print $str;
|
|---|