Several reasons. You can cuddle a ~ up to identifiers, and it doesn't disappear visually when you do so. Unary ~ came available when we unified all the XORly operators under ^ (including old unary ~, that is, 1's-complement, which implicitly XORs all the bits with 1). Plus underscore basically comes across as a very short identifier, and we wanted to reserve it for possible use as some kind of "don't care" token in logic programming, as it's used in Prolog. Or maybe we'll think of some other use for it. (I can guarantee you that it won't be the current stat buffer as it is in Perl 5, though, since you can put a stat result into any variable now.)
But, of course, the main reason is that ~ looks like a piece of string. :-) | [reply] |
I'm not quite sure why you explained where the plus went, since the original choice for string addition was the underscore .. So why did that particular one get disgarded?
I haven't tried explaining why the tilde glyph is used, but instead why having a universal glyph for string operations is useful. Sorry if the title mislead you.
I do say something about why that glyph isn't dot, but even for that I'm not mentioning all there is: the small size of the dot makes it too easy to overlook or to be a semi-meta-operator and OO takes precedence over concatenation.
Underscore has many of the problems dot has, and added to that the many problems that a \w character brings along.
I explain plus first, because tilde is the string version of that operator, and I think the consistency in that is very important, and much easier to explain by waiting with the promised subject. Otherwise, the explanation of plus would have come after, and not be an essential part of the article anymore, but instead an appendix that gets less attention.
| [reply] |