You know how to look something up in a dictionary? Well, then...

String comparson happens like this: the computer skips those characters at the front of both strings where they are equal, and it stops either at the end of the shortest of the two strings (if they have the same length, then they're equal, otherwise the shortest string comes first) or at the first character where they are different, and there, it's the "smallest" character that determines which string comes first.

The most easy way to compare characters in the computer is to compare by their character code: each character has a number assigned to it. It is stored that way: as numbers, which may be a single byte, or several bytes together representing a number.

The most common character set in modern computer systems is ASCII, or, something based on ASCII, like ISO-Latin-1, or, by extension, on Unicode.

According to ASCII, letters are ordered in order of the alphabet, which is handy, but upper case letters come first, and there are a few other characters in between them.

So the sort order of ordinary strings may not exactly e as you expect. Well, at least a space has the lowest character code of all printable characters, which is also nice. But a "Z" comes before "a" and that is not so nice; worse still, accented characters come very much farther down.

The ideal sorting order (or "collation order", as it is also known) for humans isn't uniform, actually depends on the language used.

That's why they came up with locales, so you can sort strings according to your own language.

(Actually it's not even that simple, as a locale may count several characters as one, or vice versa. Have you lost your head, yet? :) That's normal, I assure you.)


In reply to Re: comparision operators by bart
in thread comparision operators by rob171171

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.