Строка сравнивает “логику”

На Unix:

обычно Вы запускаете cpan в Вашей оболочке:

# cpan

и тип

install Chocolate::Belgian

или в краткой форме:

cpan Chocolate::Belgian

В Windows :

при использовании ActivePerl в Windows, страница в минуту (Диспетчер пакетов Perl) имеет большую часть той же функциональности как CPAN.pm.

Пример:

# ppm
ppm> search net-smtp
ppm> install Net-SMTP-Multipart

видят , Как я устанавливаю модули Perl? в CPAN FAQ

Много дистрибутивов поставляют много модулей жемчуга как пакеты.

  • Debian/Ubuntu: apt-cache search 'perl
  • Дуга Linux: pacman -Ss '^perl-'
  • хинду: категория dev-perl

Вы должны всегда , предпочитают их, поскольку Вы извлекаете выгоду из автоматического (безопасность) обновления и простота [1 141] удаление . Это может быть довольно хитро с сам инструмент cpan .

Для хинду существует хороший инструмент, названный g-cpan, который создает/устанавливает модуль из CPAN и создает хинду пакет ( ebuild) для Вас.

  • Дуга Linux: pacman -Ss '^perl-'
  • хинду: категория dev-perl
  • Вы должны всегда , предпочитают их, поскольку Вы извлекаете выгоду из автоматического (безопасность) обновления и простота [1 141] удаление . Это может быть довольно хитро с сам инструмент cpan .

    Для хинду существует хороший инструмент, названный g-cpan, который создает/устанавливает модуль из CPAN и создает хинду пакет ( ebuild) для Вас.

    6
    задан Justin R. 7 December 2009 в 21:47
    поделиться

    11 ответов

    "1" is equal to "1".

    "0" comes before "2" (so "1040" < "12000").

    "4" comes after "0" (so "1040" > "10000").

    23
    ответ дан 8 December 2019 в 02:07
    поделиться

    The fancy word here describing this ordering is "lexicographical order" (and sometimes "dictionary order"). In everyday language we just refer to it as "alphabetical order". What this means is that we place first an ordering on our alphabet (A, B, ... Z, etc.) and then to compare two words over this alphabet we compare one character at a time until we find two non-equal characters in the same position and return the comparison between these two characters.

    Example: The "natural" ordering on the alphabet { A, B, C, ..., Z } is that A < B < C < ... < Z. Given two words s = s_1s_2...s_m and t = t_1t_2...t_n we compare s_1 to t_1. If s_1 < t_1 we say that s < t. If s_1 > t_1 we say that s > t. If s_1 = t_1 we recurse on the words s_2...s_m and t_2...t_n. For this to work we say that the empty string is less than all non-empty strings.

    In the old days, before Unicode and the like, the ordering on our symbols was just the ordering for the ASCII character codes. So then we have 0 < 1 < 2 < ... < 9 < ... < A < B < C < ... Z < ... < a < b < c < ... < z. It's more complicated in the days of Unicode, but the same principle applies.

    Now, what all this means is that if we want to compare 1040 and 12000 we would use the following:

    1040 compare to 12000 is equal to 040 compare to 2000 which gives 040 < 2000 because 0 < 2 so that, finally, 1040 < 12000.

    1040 compare to 10000 is equal to 040 compare to 0000 is equal to 40 compare to 000 which gives 40 > 000 because 4 > 0 so that, finally, 1040 > 10000.

    The key here is that these are strings and do not have a numerical meaning; they are merely symbols and we have a certain ordering on our symbols. That is, we could achieve exactly the same answer if we replaced 0 by A, 1 by B, ..., and 9 by J and said that A < B < C < ... < J. (In this case we would be comparing BAEA to BAAAA and BAEA to BCAAA. )

    8
    ответ дан 8 December 2019 в 02:07
    поделиться

    Думайте в алфавитном порядке.

    6
    ответ дан 8 December 2019 в 02:07
    поделиться

    The strings are compared, one character at a time, from left to right:

    10000
    1040
    12000
    

    There's nothing wrong with comparing strings of different lengths.

    4
    ответ дан 8 December 2019 в 02:07
    поделиться

    It compares the "numbers" on a character by character basis. In the first case, "1" == "1", but then "0" < "2" in ASCII (and as an integer) so it returns true.

    In the second case, 1==1, 0==0, but 4 > 0, so it returns false.

    And there's nothing wrong with comparing strings of a different length... but you should use the appropriate string comparison method.

    2
    ответ дан 8 December 2019 в 02:07
    поделиться

    You're experiencing lexicographical ordering.

    There are some generalized algorithms for this ordering in the book Elements of Programming. Search for the word lexicographical.

    4
    ответ дан 8 December 2019 в 02:07
    поделиться

    In C, string comparisons are done character by character. In the first case, the first characters of the stings are equal, so it comes down to the second character: '0' is < '2', so "1040" < "12000". In the second case, the first two characters of the strings are equal, so the third character is the basis -- '4' > '0', so "1040" > "10000".

    If you want them compared as numbers, you'll need to convert them to numbers first, then do the comparison.

    1
    ответ дан 8 December 2019 в 02:07
    поделиться

    It compares each character since you are comparing strings. If you wish to compare the numbers, then make them a numerical type.

    0
    ответ дан 8 December 2019 в 02:07
    поделиться

    "10000" <= "1040" <= "12000" in the same way that "fabricate" <= "fact" <= "foolish".

    0
    ответ дан 8 December 2019 в 02:07
    поделиться

    To expand on the John P's answer, think of the strings as words, and read them left-to-right.

    To look at it another way,

    BAEA would come before BCAAA but after BAAAA

    1
    ответ дан 8 December 2019 в 02:07
    поделиться

    Как насчет того, чтобы сделать их одинаковой длины?

    Что бы объединить числа и альфа

    1040 становится 01040

    01040 < 12000 теперь это имеет смысл

    возможно, именно поэтому он посчитал неправильным сравнивать строки разной длины Если строки являются числами, они должны иметь одинаковую длину

    0
    ответ дан 8 December 2019 в 02:07
    поделиться
    Другие вопросы по тегам:

    Похожие вопросы: