ASCII has nothing to do with it. You can use those operators on any string of bytes, whether the data is ASCII, the result of inet_aton or a struct to pass to a system call. The operators work independantly of how the data is interpreted.

Now, $letter ^ ' ' will not toggle the case of the letter in all encodings, but that's a (simple) algorithm that uses ^ and not ^ proper.

Here's an example which demonstrates that ^ work no matter how the data was encoded:

use Socket qw( inet_aton inet_ntoa ); my $ip = inet_aton('10.0.0.155'); my $mask = inet_aton('255.255.255.240'); my $broadcast = $ip | ~$mask; print(inet_ntoa($broadcast), "\n"); # 10.0.0.159

It's definitely a language feature, and I believe an uncommon one. You can't do that in C or Java, for example.


In reply to Re^8: Incrementing a large number without Math::BigInt by ikegami
in thread Incrementing a large number without Math::BigInt by Cap'n Steve

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.