Like he said, it uses C under the hood. Now C doesn't store the length of a string anywhere. Instead, each time, it scans the string (which is just an array of characters, of unspecified length) looking for a special "end of string" character. And that character is chr(0). So when C is processing the string, it just stops when it sees a chr(0). And the way it does that, is hideously simple: the value of the character, which in C is pretty much a small integer, when taken as a boolean value(= true or false), is false — as an integer it's 0. All other characters are nonzero, thus true.
This character is not special in Perl, because Perl does store the length of each string somewhere.
And yes, IMnshO this is a serious shortcoming in C. | [reply] |
C doesn't store the length of a string anywhere.
C doesnt have a string type at all. And IMO null-terminated character arrays have proven to be the most expensive design-fault in the entire history of computing, costing billions per year. In this respect I think that history has proven that Wirth was right and the Kernigham and Ritchie were wrong. Which I guess makes 1 for 30 or something :-)
---
$world=~s/war/peace/g
| [reply] |