Monday, September 13, 2010

Comparison operators in perl


cmp --String comparison, returning -1, 0, or 1.
<=>    Numeric comparison, returning -1, 0, or 1. (looks like flying saucer)

 =~       Certain operations search or modify the string "$_" by default. This operator makes that kind of operation work on some other string. The right argument is a search pattern, substitution, or translation. The left argument is what is supposed to be searched, substituted, or translated instead of the default "$_". The return value indicates the success of the operation. (If the right argument is an expression other than a search pattern, substitution, or translation, it is interpreted as a search pattern at run time. This is less efficient than an explicit search, since the pattern must be compiled every time the expression is evaluated.) The precedence of this operator is lower than unary minus and autoincrement/decrement, but higher than everything else.


!~       Just like =~ except the return value is negated.

No comments:

Post a Comment