6/11/2023 0 Comments Perl string comparison![]() ![]() Which compares two values and tests whether they are equal.Įxample of a comparison operator. The value by -1, as illustrated by this example:Ībout the equality comparison operator ( =), Which appears between two values.) It is equivalent to multiplying (This distinguishes it from the subtraction operator, The unary negation operator is a - character in front ofĪ single value. $x = 25 % 0.1 # error: 0.1 is converted to 0 Non-integers are convertedīecause division by 0 is impossible, you can't put a 0 to the In this case, 25 divided by 4 yields 6, with a remainder of 1. The remainder operator retrieves the remainder resultingįrom the division of one integer by another. In this example, the exponent is too large to be stored on most machines. DON'T produce a result that is larger than the largest floating-point number your machine can understand: Perl does not understand complex numbers. The result of this expression is a complex (non-real) number (just as, for instance, the square root of -2 is a complex number). ** 32 - 1, and the latter is equivalent to 2ĭON'T use the exponent operator with a negative base and a non-integer exponent: (the largest number that can be stored in a 32-bit unsigned integer)Īnd 2,147,483,647 (the largest number that can be stored in aģ2-bit signed integer). If you have to use, or be aware of, numbers such as 4,294,967,295 The program shown in Listing 4.1 is useful A program that prints out the powers of two.ģ: # this program asks for a number, n, and prints 2 to theĦ: print ("Enter the exponent to use:\n") ĩ: print ("Two to the power $exponent is ", Listing 4.1 shows an example of a simple program that uses theĮxponential operator. You can use the exponent operator with non-integer or negativeĥ ** 2.5 # this is 25 * the square root of 5 Is multiplied by itself, and the result is stored in $x. Here are some other simple examples of the The number to the right,Ĭalled the exponent, is the number of times the multiplication Is the number to be repeatedly multiplied. When an exponentiation operator is employed, the base value Note that the following statements are equivalent, but the first Statement assigns 16 to the scalar variable $x. Means "take four copies of two and multiply them." This Provides a convenient way to multiply a number by itself repeatedly.įor example, here is a simple Perl statement that uses the exponentiation ![]() ![]() Ones you've already seen, they are quite easy to use. Perl also supports three other arithmetic operations:Īlthough these operators aren't as intuitively obvious as the Subtraction, multiplication, and division. The way you expect them to: They perform the operations of addition, The arithmetic operators that you have seen so far-the , The other integer- and string-comparison operators.Today, you learn about the rest of the operators that Perl provides,Īs well as about operator associativity and precedence. On Day 2, "Basic Operators and Control Flow," you learned The String Concatenation and Repetition Operators The Autoincrement Operator Post-Increment String Comparison Versus Integer Comparison Day 4 - More Operators Chapter 4 More Operators ![]()
0 Comments
Leave a Reply. |