Example | Type | Result | $a+$b | Addition | Sum of $a and $b | $a-$b | Subtraction | Result of $b subtracted from $a | $a*$b | Multiplication | Product of $a and $b | $a/$b | Division | Result of $a divided by $b | $a%$b | Modulus | Remainder when $a is divided by $b | $a**$b | Exponentiation | $a to the power of $b | Type | Numeric | String | Greater Than | > | gt | Less Than | < | lt | Equal to | == | eq | Not equal | != | ne | Less than or equal to | <= | le | Greater than or equal to | >= | ge | Examples | Short Version | Textual Version | Meaning | $a and $b; $a && b | && | and | returns true if $a and $b are both defined and nonzero | $a or $b; $a||$b | || | or | returns true if either $a or $b is defined and nonzero | !$a; not $a | ! | not | returns the opposite of what an expression would otherwise | Operators: arithmetic and otherwise or Code |
Replies are listed 'Best First'. | by on Apr 24, 2000 at 22:31 UTC | Typo in 7th line? Perhaps ought to be #$a=$a-2; | | by (Initiate) on Apr 20, 2005 at 00:55 UTC | | | by on Jan 12, 2001 at 21:10 UTC | | | by (Initiate) on Jun 02, 2000 at 02:52 UTC | | | by on Jun 29, 2001 at 01:14 UTC | | | by on Mar 17, 2003 at 17:04 UTC | | | by (Curate) on Jun 15, 2004 at 03:10 UTC | e 222 | |
Back to Tutorials www . com | www . net | www . org - Seekers of Perl Wisdom
- Cool Uses for Perl
- Meditations
- PerlMonks Discussion
- Categorized Q&A
- Obfuscated Code
- Perl Poetry
- PerlMonks FAQ
- Guide to the Monastery
- What's New at PerlMonks
- Voting/Experience System
- Other Info Sources
- Nodes You Wrote
- My Watched Nodes
- Super Search
- List Nodes By Users
- Newest Nodes
- Recently Active Threads
- Selected Best Nodes
- Worst Nodes
- Saints in our Book
- Random Node
- Today I Learned
- The St. Larry Wall Shrine
- Offering Plate
- Planet Perl
- Perl Weekly
- Perl Mongers
- Perl documentation
2024 2025 2026-2027 2028-2030 One microsecond after Skynet becomes self-aware Results (21 votes) . Check out past polls . | • | -->‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, . | Home » Perl Operators Perl OperatorsSummary : in this tutorial, you’ll learn about Perl operators including numeric operators, string operators, and logical operators. Numeric operatorsPerl provides numeric operators to help you operate on numbers including arithmetic, Boolean and bitwise operations. Let’s examine the different kinds of operators in more detail. Arithmetic operatorsPerl arithmetic operators deal with basic math such as adding, subtracting, multiplying, diving, etc. To add (+ ) or subtract (-) numbers, you would do something as follows: To multiply or divide numbers, you use divide (/) and multiply (*) operators as follows: When you combine adding, subtracting, multiplying, and dividing operators together, Perl will perform the calculation in an order, which is known as operator precedence. The multiply and divide operators have higher precedence than add and subtract operators, therefore, Perl performs multiplying and dividing before adding and subtracting. See the following example: Perl performs 20/2 and 5*2 first, therefore you will get 10 + 10 – 10 = 10. You can use brackets () to force Perl to perform calculations based on the precedence you want as shown in the following example: To raise one number to the power of another number, you use the exponentiation operator (**) e.g., 2**3 = 2 * 2 * 2. The following example demonstrates the exponentiation operators: To get the remainder of the division of one number by another, you use the modulo operator (%). It is handy to use the modulo operator (%) to check if a number is odd or even by dividing it by 2 to get the remainder. If the remainder is zero, the number is even, otherwise, the number is odd. See the following example: Bitwise OperatorsBitwise operators allow you to operate on numbers one bit at a time. Think of a number as a series of bits e.g., 125 can be represented in binary form as 1111101 . Perl provides all basic bitwise operators including and (&), or (|), exclusive or (^) , not (~) operators, shift right (>>), and shift left (<<) operators. The bitwise operators perform from right to left. In other words, bitwise operators perform from the rightmost bit to the leftmost bit. The following example demonstrates all bitwise operators: If you are not familiar with bitwise operations, we are highly recommended you check out bitwise operations on Wikipedia . Comparison operators for numbersPerl provides all comparison operators for numbers as listed in the following table: Equality | Operators |
---|
Equal | == | Not Equal | != | Comparison | <=> | Less than | < | Greater than | > | Less than or equal | <= | Greater than or equal | >= |
All the operators in the table above are obvious except the number comparison operator <=> which is also known as spaceship operator. The number comparison operator is often used in sorting numbers. See the code below: The number operator returns: - 1 if $a is greater than $b
- 0 if $a and $b are equal
- -1 if $a is lower than $b
Take a look at the following example: String operatorsString comparison operators. Perl provides the corresponding comparison operators for strings. Let’s take a look a the table below: Equality | Operators |
---|
Equal | eq | Not Equal | ne | Comparison | cmp | Less than | lt | Greater than | gt | Less than or equal | le | Greater than or equal | ge |
String concatenation operatorsPerl provides the concatenation ( . ) and repetition ( x ) operators that allow you to manipulate strings. Let’s take a look at the concatenation operator (.) first: The concatenation operator (.) combines two strings together. A string can be repeated with the repetition ( x ) operator: The chomp() operatorThe chomp() operator (or function ) removes the last character in a string and returns a number of characters that were removed. The chomp() operator is very useful when dealing with the user’s input because it helps you remove the new line character \n from the string that the user entered. The <STDIN> is used to get input from users. Logical operatorsLogical operators are often used in control statements such as if , while , given, etc., to control the flow of the program. The following are logical operators in Perl: - $a && $b performs the logic AND of two variables or expressions. The logical && operator checks if both variables or expressions are true.
- $a || $b performs the logic OR of two variables or expressions. The logical || operator checks whether a variable or expression is true.
- !$a performs the logic NOT of the variable or expression. The logic ! operator inverts the value of the following variable or expression. In the other words, it converts true to false or false to true .
You will learn how to use logical operators in conditional statements such as if , while and given . In this tutorial, you’ve learned some basic Perl operators. These operators are very important so make sure that you get familiar with them. - Perl - Home
- Perl - Introduction
- Perl - Comments
- Perl - Operators
- Perl - If Else
- Perl - Unless Else
- Perl - Given Statement
- Perl - While Loop
- Perl - Until Loop
- Perl - For Loop
- Perl - Foreach Loop
- Perl - goto Statement
- Perl - Next Statement
- Perl - Last Statement
- Perl - Continue Statement
- Perl - Redo Statement
- Perl - Math Functions
- Programming Languages
- Web Technologies
- Database Technologies
- Microsoft Technologies
- Python Libraries
- Data Structures
- Interview Questions
- PHP & MySQL
- C++ Standard Library
- C Standard Library
- Java Utility Library
- Java Default Package
- PHP Function Reference
Perl - assignment operators exampleThe example below shows the usage of assignment and compound assignment operators: - = Assignment operator
- += Addition AND assignment operator
- -= Subtraction AND assignment operator
- *= Multiply AND assignment operator
- /= Division AND assignment operator
- %= Modulo AND assignment operator
- **= Exponent AND assignment operator
The output of the above code will be: - Data Structures Tutorial
- Algorithms Tutorial
- JavaScript Tutorial
- Python Tutorial
- MySQLi Tutorial
- Java Tutorial
- Scala Tutorial
- C++ Tutorial
- C# Tutorial
- PHP Tutorial
- MySQL Tutorial
- SQL Tutorial
- PHP Function reference
- C++ - Standard Library
- Java.lang Package
- Ruby Tutorial
- Rust Tutorial
- Swift Tutorial
- Perl Tutorial
- HTML Tutorial
- CSS Tutorial
- AJAX Tutorial
- XML Tutorial
- Online Compilers
- QuickTables
- NumPy Tutorial
- Pandas Tutorial
- Matplotlib Tutorial
- SciPy Tutorial
- Seaborn Tutorial
- Trending Now
- Foundational Courses
- Data Science
- Practice Problem
- Machine Learning
- System Design
- DevOps Tutorial
Perl | Operators | Set – 1Operators are the main building block of any programming language. Operators allow the programmer to perform different kinds of operations on operands. In Perl , operators symbols will be different for different kind of operands(like scalars and string). Operators Can be categorized based upon their different functionality: Arithmetic Operators Relational Operators Logical Operators Bitwise Operators Assignment Operators Ternary Operator These are used to perform arithmetic/mathematical operations on operands. - Addition: ‘ + ‘ operator is used to add the values of the two operands. For Example:
- Subtraction: ‘ – ‘ operator is used to subtract right hand operand from left hand operand. For Example:
- Multiplication: ‘ * ‘ operator is used to multiplies the value on either side of the operator. For Example:
- Division Operator: ‘ / ‘ operator returns the remainder when first operand is divided by the second. For Example:
- Modulus Operator: ‘ % ‘ operator is used to divide left hand operand from right operand and returns remainder. For Example:
- Exponent Operator: ‘ ** ‘ operator is used to perform the exponential(power) calculation on operands. For Example:
Program: To demonstrate the arithmetic operators Relational operators are used for comparison of two values. These operators will return either 1 (true) or nothing(i.e. 0(false)) . Sometimes these operators are also termed as the Equality Operators . These operators have the different symbols to operate on strings. To know about Comparison Operators operation on String you can refer to this . - Equal To Operator: ‘==’ Check if two values are equal or not. If equals then return 1 otherwise return nothing.
- Not equal To Operator: ‘!=’ Check if the two values are equal or not. If not equal then returns 1 otherwise returns nothing.
- Comparison of equal to Operator: ‘< = >’ If left operand is less than right then returns -1, if equal returns 0 else returns 1.
- Greater than Operator: ‘>’ If left operand is greater than right returns 1 else returns nothing.
- Less than Operator: ‘<‘ If left operand is lesser than right returns 1 else returns nothing.
- Greater than equal to Operator: ‘>=’ If left operand is greater than or equal to right returns 1 else returns nothing.
- Less than equal to Operator: ‘<=’ If left operand is lesser than or equal to right returns 1 else returns nothing.
Program: To illustrate the Relational Operators in Perl Output: These operators are used to combine two or more conditions/constraints or to complement the evaluation of the original condition in consideration. - Logical AND: The ‘ and ’ operator returns true when both the conditions in consideration are satisfied. For example, $a and $b is true when both a and b both are true (i.e. non-zero). You can use also && .
- Logical OR: The ‘ or ’ operator returns true when one (or both) of the conditions in consideration is satisfied. For example, $a or $b is true if one of a or b is true (i.e. non-zero). Of course, it gives result “true” when both a and b are true. You can use also ||
- Logical NOT: The ‘not’ operator will give 1 if the condition in consideration is satisfied. For example, not($d) is true if $d is 0.
Program: To demonstrate the working of Logical Operators: These operators are used to perform the bitwise operation. It will first convert the number into bits and perform the bit-level operation on the operands. - & (bitwise AND) Takes two numbers as operands and does AND on every bit of two numbers. The result of AND is 1 only if both bits are 1. For example
- | (bitwise OR) Takes two numbers as operands and does OR on every bit of two numbers. The result of OR is 1 any of the two bits is 1. For example
- ^ (bitwise XOR) Takes two numbers as operands and does XOR on every bit of two numbers. The result of XOR is 1 if the two bits are different. For example
- ~ (Complement Operator) This is unary operator act as flipping bits. It’s work is to reverse the bits and gives result using 2’s complement form due to a signed binary number.
- (<<) Binary Left Shift Operator will takes two numbers, left shifts the bits of the first operand, the second operand decides the number of places to shift. It performs multiplication of the left operand by the number of times specified by the right operand. For Example:
- (>>)Binary Right Shift Operator will take two numbers, right shifts the bits of the first operand, the second operand decides the number of places to shift. It performs division of the left operand by the number of times specified by right operand. For Example:
Program: To demonstrate the working of bitwise operators: Assignment operators are used to assigning a value to a variable. The left side operand of the assignment operator is a variable and right side operand of the assignment operator is a value. Different types of assignment operators are shown below: - “=”(Simple Assignment) : This is the simplest assignment operator. This operator is used to assign the value on the right to the variable on the left. Example :
- “+=”(Add Assignment) : This operator is combination of ‘+’ and ‘=’ operators. This operator first adds the current value of the variable on left to the value on the right and then assigns the result to the variable on the left. Example :
- If initially value stored in a is 5. Then ($a += 6) = 11.
- “-=”(Subtract Assignment) : This operator is combination of ‘-‘ and ‘=’ operators. This operator first subtracts the current value of the variable on left from the value on the right and then assigns the result to the variable on the left. Example :
- If initially value stored in a is 8. Then ($a -= 6) = 2.
- “*=”(Multiply Assignment) : This operator is combination of ‘*’ and ‘=’ operators. This operator first multiplies the current value of the variable on left to the value on the right and then assigns the result to the variable on the left. Example :
- If initially value stored in a is 5. Then ($a *= 6) = 30.
- “/=”(Division Assignment) : This operator is combination of ‘/’ and ‘=’ operators. This operator first divides the current value of the variable on left by the value on the right and then assigns the result to the variable on the left. Example :
- If initially value stored in a is 6. Then ($a /= 2) = 3.
- “%=”(Modulus Assignment) : This operator is combination of ‘%’ and ‘=’ operators. This operator first modulo the current value of the variable on left by the value on the right and then assigns the result to the variable on the left. Example :
- If initially value stored in a is 6. Then ($a %= 2) = 0.
- “**=”(Exponent Assignment) : This operator is combination of ‘**’ and ‘=’ operators. This operator first exponent the current value of the variable on left by the value on the right and then assigns the result to the variable on the left. Example :
- If initially, value stored in a is 6. Then ($a **= 2) = 36.
Program: To demonstrate the working of Assignment Operators It is a conditional operator which is a shorthand version of if-else statement. It has three operands and hence the name ternary. It will return one of two values depending on the value of a Boolean expression. Syntax: Explanation: Example: Note: In the Ternary operator the condition can be any expression also which can make by using the different operators like relational operators, logical operators, etc. Please Login to comment...Similar reads. - perl-basics
- perl-operators
Improve your Coding Skills with PracticeWhat kind of Experience do you want to share?Perl in a Nutshell byGet full access to Perl in a Nutshell and 60K+ other titles, with a free 10-day trial of O'Reilly. There are also live events, courses curated by job role, and more. Table 4.3 lists all the Perl operators from highest to lowest precedence and indicates their associativity. Table 4-3. Perl Associativity and Operators, Listed by Precedence Associativity | Operators |
---|
Left | Terms and list operators (leftward) | Left | (method call, dereference) | Nonassociative | (autoincrement, autodecrement) | Right | (exponentiation) | Right | and unary and (logical not, bit-not, reference, unary plus, unary minus) | Left | (matches, doesn’t match) | Left | (multiply, divide, modulus, string replicate) | Left | (addition, subtraction, string concatenation) | Left | (left bit-shift, right bit-shift) | Nonassociative | Named unary operators and file-test operators | Nonassociative | (less than, greater than, less than or equal to, greater than or equal to, and their string equivalents. | Nonassociative | (equal to, not equal to, signed comparison, and their string equivalents) | Left | (bit-and) | Left | (bit-or, bit-xor) | Left | (logical AND) | Left | (logical OR) | Nonassociative | (range) | Right | (ternary conditional) | Right | and so on (assignment operators) | Left | (comma, arrow comma) | Nonassociative | List operators (rightward) | Right | (logical not) | Left | (logical and) | Left | (logical or, xor) |
You can make your expressions clear by using parentheses to group any part of an expression. Anything in parentheses will be evaluated as a single unit within a larger expression. With very few exceptions, Perl operators act upon scalar values only, not upon list values. Terms that take highest precedence in Perl include variables, quote and quotelike operators, any expression in parentheses, and any function whose arguments are in parentheses. A list operator is a function that can take a list of values as its argument. List operators take highest precedence when considering what’s to the left of them. They have considerably lower precedence when looking at their right side, which is the expected result. Also parsed as high-precedence terms are the do{} and eval{} constructs, as well as subroutine and method calls, the anonymous array and hash composers ( [] and {} ), and the anonymous subroutine composer sub{} . A unary operator is a function that takes a single scalar value as its argument. Unary operators have a lower precedence than list operators because they only expect and take one value. The Arrow OperatorThe arrow operator is a dereference operator. It can be used for references to arrays, hashes, code references, or for calling methods on objects. See the discussion of references in Chapter 7 . Unary OperatorsUnary ! performs logical negation, that is, “not.” The not operator is a lower-precedence version of ! . Unary - performs arithmetic negation if the operand is numeric. If the operand is an identifier, then a string consisting of a minus sign concatenated with the identifier is returned. Otherwise, if the string starts with a plus or minus, a string starting with the opposite sign is returned. Unary ~ performs bitwise negation, that is, one’s complement. For example, on a 32-bit machine, ~0xFF is 0xFFFFFF00 . If the argument to ~ is a string instead of a number, a string of identical length is returned, but with all the bits of the string complemented. Unary + has no semantic effect whatsoever, even on strings. It is syntactically useful for separating a function name from a parenthesized expression that would otherwise be interpreted as the complete list of function arguments. Unary \ creates a reference to whatever follows it (see “References and Complex Data Structures” later in this chapter). Do not confuse this behavior with the behavior of backslash within a string. The \ operator may also be used on a parenthesized list value in a list context, in which case it returns references to each element of the list. Arithmetic OperatorsBinary ** is the exponentiation operator. Note that it binds even more tightly than unary minus, so -2**4 is -(2**4) , not (-2)**4 . Note also that ** has right associativity, so: evaluates to 2 to the 81st power, not 8 to the 4th power. The * (multiply) and / (divide) operators work exactly as you might expect, multiplying or dividing their two operands. Division is done in floating-point mode, unless integer mode in enabled (via use integer ). The % (modulus) operator converts its operands to integers before finding the remainder according to integer division. For the same operation in floating-point mode, you may prefer to use the fmod() function from the POSIX module (see Chapter 8 ). Comparison OperatorsRelational operators. Perl has two classes of relational operators. One class operates on numeric values, and the other operates on string values. String comparisons are based on the ASCII collating sequence. Relational operators are nonassociative, so $a < $b < $c is a syntax error. Numeric | String | Meaning |
---|
| | Greater than | | | Greater than or equal to | | | Less than | | | Less than or equal to |
Equality operatorsThe equal and not-equal operators return 1 for true, and "" for false (just as the relational operators do). The <=> and cmp operators return -1 if the left operand is less than the right operand, 0 if they are equal, and +1 if the left operand is greater than the right. Numeric | String | Meaning |
---|
| | Equal to | | | Not equal to | | | Comparison, with signed result |
Autoincrement and AutodecrementIf placed before a variable, the ++ and -- operators increment or decrement the variable before returning the value, and if placed after, they increment or decrement the variable after returning the value. Assignment OperatorsPerl recognizes the following operators for assigning a value to a variable: Each operator requires a variable on the left side and some expression on the right side. For the simple assignment operator, = , the value of the expression is stored into the designated variable. For the other operators, Perl evaluates the expression: as if it were written: except that $var is evaluated only once. For example: Pattern Match OperatorsBinary =~ binds a scalar expression to a pattern match, substitution, or translation. These operations search or modify the string $_ by default. Binary !~ is just like =~ except the return value is negated in the logical sense. The following expressions are functionally equivalent: See Section 4.6 later in this chapter. File Test OperatorsA file test operator is a unary operator that tests a filename or a filehandle. Operator | Meaning |
---|
| File is readable by effective uid/gid. | | File is writable by effective uid/gid. | | File is executable by effective uid/gid. | | File is owned by effective uid. | | File is readable by real uid/gid. | | File is writable by real uid/gid. | | File is executable by real uid/gid. | | File is owned by real uid. | | | | File exists. | | File has zero size. | | File has non-zero size (returns size). | | | | File is a plain file. | | File is a directory. | | File is a symbolic link. | | File is a named pipe (FIFO). | | File is a socket. | | File is a block special file. | | File is a character special file. | | Filehandle is opened to a tty. | | | | File has setuid bit set. | | File has setgid bit set. | | File has sticky bit set. | | | | File is a text file. | | File is a binary file (opposite of ). | | | | Age of file (at startup) in days since modification. | | Age of file (at startup) in days since last access. | | Age of file (at startup) in days since inode change. |
Logical OperatorsPerl provides the && (logical AND) and || (logical OR) operators. They evaluate from left to right testing the truth of the statement. Example | Name | Result |
---|
| And | if is false, otherwise | | Or | if is true, otherwise |
For example, an oft-appearing idiom in Perl programs is: In this case, Perl first evaluates the open function. If the value is true (because somefile was successfully opened), the execution of the die function is unnecessary and is skipped. Perl also provides lower-precedence and and or operators that are more readable. Bitwise OperatorsPerl has bitwise AND, OR, and XOR (exclusive OR) operators: & , | , and ^ . These operators work differently on numeric values than they do on strings. If either operand is a number, then both operands are converted to integers, and the bitwise operation is performed between the two integers. If both operands are strings, these operators do bitwise operations between corresponding bits from the two strings. Miscellaneous OperatorsRange operator. The .. range operator is really two different operators depending on the context. In a list context, it returns a list of values counting (by ones) from the left value to the right value. In a scalar context, .. returns a Boolean value. It is false as long as its left operand is false. Once the left operand is true, the range operator stays true until the right operand is true, after which the range operator becomes false again. The right operand is not evaluated while the operator is in the false state, and the left operand is not evaluated while the operator is in the true state. The alternate version of this operator, … , does not test the right operand immediately when the operator becomes true; it waits until the next evaluation. Conditional operatorTernary ?: is the conditional operator. It works much like an if-then-else statement, but it can safely be embedded within other operations and functions. If the test_expr is true, only the if_true_expr is evaluated. Otherwise, only the if_false_expr is evaluated. Either way, the value of the evaluated expression becomes the value of the entire expression. Comma operatorIn a list context, " , " is the list argument separator and inserts both its arguments into the list. In scalar context, " , " evaluates its left argument, throws that value away, then evaluates its right argument and returns that value. The => operator is mostly just a synonym for the comma operator. It’s useful for documenting arguments that come in pairs. It also forces any identifier to the left of it to be interpreted as a string. String operatorThe concatenation operator “.” is used to add strings together: Binary x is the string repetition operator. In scalar context, it returns a concatenated string consisting of the left operand repeated the number of times specified by the right operand. In list context, if the left operand is a list in parentheses, the x works as a list replicator rather than a string replicator. This is useful for initializing all the elements of an array of indeterminate length to the same value: Get Perl in a Nutshell now with the O’Reilly learning platform. O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers. Don’t leave empty-handedGet Mark Richards’s Software Architecture Patterns ebook to better understand how to design components—and how they should interact. It’s yours, free.Check it out now on O’ReillyDive in for free with a 10-day trial of the O’Reilly learning platform—then explore all the other resources our members count on to build skills and solve problems every day. 3,000,000+ delegates 15,000+ clients 1,000+ locations - KnowledgePass
- Log a ticket
01344203999 Available 24/7 Perl Operator: A Comprehensive OverviewDiscover this blog to explore an in-depth analysis of Perl Operator. This blog will also cover different types, including arithmetic, string, logical, and bitwise operators, explaining their syntax and usage. This blog also emphasises their role in controlling program flow and manipulating data, highlighting best practices for efficient coding in Perl. Exclusive 40% OFF Training Outcomes Within Your Budget!We ensure quality, budget-alignment, and timely delivery by our expert instructors. Share this Resource- Object Oriented Programming (OOPs) Course
- Elixir Programming Language Training
- D Programming Language Training
- Clojure Programming Language Training
- Rust Course
Perl is a versatile scripting language that offers a rich set of operators and essential tools for programmers to manipulate data and control program flow. Perl Operators are categorised into various types, such as arithmetic for mathematical operations, string operators for text manipulation, logical operators for decision-making, and more. Each type is unique, allowing for addition, concatenation, comparison, and condition evaluation. Understanding these operators is crucial for effective Perl programming, as they are fundamental in constructing expressions and enabling complex functionalities. Do you want to learn more about these Operators? Read this blog to learn more about Perl Operators and explore these powerful Operators and how they are used. Table of Contents 1) What is Perl Operator? 2) Arithmetic Operators 3) Equality Operators 4) Assignment Operators 5) Bitwise Operators 6) Logical Operators 7) Conclusion What is a Perl Operator? Understanding Perl Operators is essential for any programmer working with the language. They allow for executing complex operations and control structures, rendering Perl an effective tool for various applications, from web development to system administration. In Perl, an Operator is a key element for executing specific operations on operands, which can be values or variables. These Operators are integral to forming expressions in Perl, enabling data manipulation and dictating program logic flow. The richness and variety of operators in Perl make it a versatile language suitable for various programming tasks. Operators in Perl are categorised into several types, each with its unique role. Arithmetic Operators, for instance, are used for basic mathematical operations like addition, subtraction, multiplication, and division. These are fundamental for any calculations within the program. String operators, on the other hand, are designed specifically for string manipulation, allowing for operations like concatenation, repetition, and string comparison. Arithmetic Operators Arithmetic operators, including Perl, are fundamental in any programming language as they allow for basic mathematical operations within the code. These operators enable the manipulation of numerical values, forming the backbone of many computational tasks. In Perl, arithmetic operators are intuitive and follow conventional mathematical notation, making them accessible to both beginners and experienced programmers. a) Addition (+): The most basic arithmetic operator is addition, represented by the plus sign (+). It is used to add two or more numbers. For example, ‘$sum = $a + $b’; will add the values of ‘$a’ and ‘$b’ and store the result in ‘$sum’. my $a = 5; my $b = 3; my $sum = $a + $b; # $sum is 8 b) Subtraction (-): The subtraction operator, denoted by a minus sign (-), subtracts one number from another. For instance, ‘$difference = $a - $b’; will subtract ‘$b’ from ‘$a’ my $a = 10; my $b = 4; my $difference = $a - $b; # $difference is 6 c) Multiplication (*): Represented by an asterisk (*), the multiplication operator is used to multiply two numbers. ‘$product = $a * $b’; multiplies ‘$a’ and ‘$b’. my $a = 7; my $b = 6; my $product = $a * $b; # $product is 42 d) Division (/): The division operator, symbolised by a forward slash (/), divides one number by another. ‘$quotient = $a / $b’; will divide ‘$a’ by ‘$b’. my $a = 20; my $b = 5; my $quotient = $a / $b; # $quotient is 4 e) Modulus (%): The modulus operator, represented by a percent sign (%), is used to find the remainder of a division operation. ‘$remainder = $a % $b’; will give the remainder when ‘$a’ is divided by ‘$b’. my $remainder = $a % $b; # $remainder is 1 f) Exponentiation (): Perl also supports exponentiation (raising a number to the power of another number) using the double asterisk operator (). ‘$power = $a ** $b’; will raise ‘$a’ to the power of ‘$b’. my $a = 2; my $power = $a ** $b; # $power is 8 g) Auto-increment (++) and Auto-decrement (--): Perl provides two very useful arithmetic operators: auto-increment (++) and auto-decrement (--). The auto-increment operator increases a number's value by one, while the auto-decrement operator decreases it by one. These operators can be used both as pre- and post-operators. my $value = 5; $value++; # $value is now 6 $value--; # $value is back to 5 h) Assignment with Arithmetic Operators: Perl combines assignment with arithmetic operators, enabling shorthand operations. For example, $a += $b; is equivalent to $a = $a + $b;. $a += 5; # $a is now 15 $a *= 2; # $a is now 30 Equality Operators In Perl, Equality Operators are essential for comparing values, a fundamental aspect of programming that allows for decision-making based on conditions. These operators test for equality or inequality, yielding Boolean values (true or false). Understanding equality operators is crucial for controlling program flow through conditional statements like ‘if’, ‘unless’, ‘while’, and others. Types of Equality Operators in Perl: Perl distinguishes between two types of equality comparisons: numeric and string. This distinction is crucial because Perl is a context-sensitive language, meaning it treats the same data differently based on the context. a) Numeric Equality Operators 1) Equal (==): This operator checks if two numbers are equal. If they are, it returns true; otherwise, it returns false. if ($a == $b) { print "a and b are equal"; 2) Not equal (!=): It tests whether two numbers are not equal. If they are different, it returns true. if ($a != $b) { print "a and b are not equal"; b) String Equality Operators 1. Equal (eq): This operator checks whether two strings are identical. It's essential to use eq instead of == when comparing strings. if ($string1 eq $string2) { print "The strings are equal"; 2. Not equal (ne): It checks if two strings are different. if ($string1 ne $string2) { print "The strings are not equal"; Assignment Operators Assignment operators in programming languages like Perl are fundamental components that simplify assigning values to variables. They are not just limited to the basic assignment but also include a range of compound assignment operators that combine arithmetic, string, and other operations with the assignment. Understanding these operators is crucial for writing concise and efficient code. a) Basic Assignment Operator 1) Equals (=): The most basic assignment operator is the equals sign (=). It assigns the value on its right to the variable on its left. my $a = 5; # Assigns 5 to $a b) Compound Assignment Operators: Perl enhances the functionality of the basic assignment operator with compound assignment operators, which combine an operation with the assignment. 1) Addition Assignment (+=): Adds the right operand to the left operand and assigns the result to the left operand. $a += 3; # Equivalent to $a = $a + 3 2) Subtraction Assignment (-=): Subtracts the right operand from the left operand and assigns the result to the left operand. $a -= 2; # Equivalent to $a = $a - 2 3) Multiplication Assignment (*=): Multiplies the left operand by the right operand and assigns the result to the left operand. $a *= 4; # Equivalent to $a = $a * 4 4) Division Assignment (/=): Divides the left operand by the right operand and assigns the result to the left operand. $a /= 2; # Equivalent to $a = $a / 2 5) Modulus Assignment (%=): Applies modulus operation and assigns the result to the left operand. $a %= 3; # Equivalent to $a = $a % 3 6) Exponentiation Assignment (**=): Raises the left operand to the power of the right operand and assigns the result back. $a **= 2; # Equivalent to $a = $a ** 2 7) String Concatenation Assignment (.=): Appends the right string operand to the left string operand. my $str = "Hello"; $str .= " World"; # $str now is "Hello World" 8) Bitwise AND Assignment (&=), Bitwise OR Assignment (|=), and Bitwise XOR Assignment (^=): These perform the corresponding bitwise operation and assign the result to the left operand. $a &= $b; # Bitwise AND $a |= $b; # Bitwise OR $a ^= $b; # Bitwise XOR Bitwise Operators Bitwise Operators are a category of operators in programming languages, such as Perl, that perform operations at the bit level on numeric values. These operators treat their operands as sequences of 32 or 64 bits (depending on the platform) and operate on them bit by bit. Understanding bitwise operators is essential for tasks involving low-level data manipulation, such as working with binary data, flags, and masks. Types of Bitwise Operators: 1) AND (&): The bitwise AND operator compares each bit of its first operand to the corresponding bit of its second operand. If both bits are 1, it sets the bit in the result to 1; otherwise, it is 0. $result = $a & $b; # Bitwise AND of $a and $b 2) OR (|): This operator compares each bit of its first operand to the corresponding bit of its second operand. If either bit is 1, it sets the result bit to 1. $result = $a | $b; # Bitwise OR of $a and $b 3) XOR (^): The bitwise XOR (exclusive OR) operator compares each bit of its first operand to the corresponding bit of its second operand. If the bits are different, it sets the result bit to 1. $result = $a ^ $b; # Bitwise XOR of $a and $b 4) NOT (~): The bitwise NOT operator inverts all the bits of its operand. $result = ~$a; # Bitwise NOT of $a 5) Left Shift ( This operator shifts all bits of its first operand to the left by the number of places specified in the second operand. New bits on the right are filled with zeros. $result = $a << $shift; # Left shift $a by $shift bits 6) Right Shift (>>): It shifts all bits of its first operand to the right. The behaviour for the leftmost bits depends on the number type and whether it's signed or unsigned. $result = $a >> $shift; # Right shift $a by $shift bits Become an expert in different Programming Languages – sign up now with our course on Programming Training ! Logical Operators Logical operators in Perl are crucial for constructing logical expressions, which are fundamental to controlling program flow through conditional statements like ‘if’, ‘while’, and ‘unless’. These operators evaluate expressions and return Boolean values (true or false) based on the logic they implement. The primary logical operators in Perl are ‘and’, ‘or’, ‘not’, ‘&&’, ‘||’, and ‘!’. Types of Logical Operators: 1) AND (&& and ‘and’): This operator returns true if both operands are true. The difference between ‘&’ and ‘and’ is their precedence, with && having a higher precedence. if ($a && $b) { # Executes if both $a and $b are true 2) OR (|| and or): The OR operator returns true if either of its operands is true. Similar to AND, ‘||’ has a higher precedence than ‘or’. if ($a || $b) { # Executes if either $a or $b is true 3) NOT (! and not): NOT is a unary operator that inverts the truth value of its operand. ! has a higher precedence than not. if (!$a) { # Executes if $a is not true (i.e., false) Do you want to learn more about Perl Programming Language? Register now for our Basic Perl Programming Training ! Conclusion Perl Operators are fundamental tools that greatly enhance the language's power and flexibility. They enable efficient data manipulation, logical decision-making, and control over program flow. Mastering these operators, from arithmetic to logical, is crucial for effective Perl scripting, allowing for concise and powerful code in various applications. Learn the concept of data reshaping with R Programming – join now for our R Programming Course ! Frequently Asked QuestionsThe most commonly used Perl operators are: a) Arithmetic Operators (+, -, *, /, %) for basic mathematical operations. b) String Operators (. for concatenation, x for repetition) for string manipulation. c) Logical Operators (&&, ||, !) for evaluating Boolean expressions and controlling program flow. Perl uses different operators for numeric and string comparison. For numeric comparison, it uses ‘==’ (equal), ‘!=’ (not equal), ‘ ’ (greater than), etc. For string comparison, it uses ‘eq’ (equal), ‘ne’ (not equal), ‘lt’ (less than), ‘gt’ (greater than), etc. This distinction ensures accurate comparisons based on the data type. Yes, Perl operators can be combined to form complex expressions. For instance, arithmetic operators can be used with assignment operators (like +=, *=) for compound assignments. Logical operators can be used to combine multiple conditions in control structures. However, it's important to remember operator precedence and use parentheses for clarity when needed. The Knowledge Academy takes global learning to new heights, offering over 30,000 online courses across 490+ locations in 220 countries. This expansive reach ensures accessibility and convenience for learners worldwide. Alongside our diverse Online Course Catalogue, encompassing 17 major categories, we go the extra mile by providing a plethora of free educational Online Resources like News updates, Blogs , videos, webinars, and interview questions. Tailoring learning experiences further, professionals can maximise value with customisable Course Bundles of TKA . The Knowledge Academy’s Knowledge Pass , a prepaid voucher, adds another layer of flexibility, allowing course bookings over a 12-month period. Join us on a journey where education knows no bounds. The Knowledge Academy offers various Programming courses , including Basic Perl Programming Training, PHP Course, and R Programming Course. These courses cater to different skill levels, providing comprehensive insights into Programming Languages . Our Programming blogs covers a range of topics related to Perl, offering valuable resources, best practices, and industry insights. Whether you are a beginner or looking to advance your Programming skills, The Knowledge Academy's diverse courses and informative blogs have you covered. Upcoming Programming & DevOps Resources Batches & DatesThu 29th Aug 2024 Thu 28th Nov 2024 Get A QuoteWHO WILL BE FUNDING THE COURSE? My employer By submitting your details you agree to be contacted in order to respond to your enquiry - Business Analysis
- Lean Six Sigma Certification
Share this courseOur biggest summer sale. We cannot process your enquiry without contacting you, please tick to confirm your consent to us for contacting you about your enquiry. By submitting your details you agree to be contacted in order to respond to your enquiry. We may not have the course you’re looking for. If you enquire or give us a call on 01344203999 and speak to our training experts, we may still be able to help with your training requirements. Or select from our popular topics - ITIL® Certification
- Scrum Certification
- Change Management Certification
- Business Analysis Courses
- Microsoft Azure Certification
- Microsoft Excel Courses
- Microsoft Project
- Explore more courses
Press esc to close Fill out your contact details below and our training experts will be in touch. Fill out your contact details below Thank you for your enquiry! One of our training experts will be in touch shortly to go over your training requirements. Back to Course Information Fill out your contact details below so we can get in touch with you regarding your training requirements. * WHO WILL BE FUNDING THE COURSE? Preferred Contact Method No preference Back to course information Fill out your training details below Fill out your training details below so we have a better idea of what your training requirements are. HOW MANY DELEGATES NEED TRAINING? HOW DO YOU WANT THE COURSE DELIVERED? Online Instructor-led Online Self-paced WHEN WOULD YOU LIKE TO TAKE THIS COURSE? Next 2 - 4 months WHAT IS YOUR REASON FOR ENQUIRING? Looking for some information Looking for a discount I want to book but have questions One of our training experts will be in touch shortly to go overy your training requirements. Your privacy & cookies!Like many websites we use cookies. We care about your data and experience, so to give you the best possible experience using our site, we store a very limited amount of your data. Continuing to use this site or clicking “Accept & close” means that you agree to our use of cookies. Learn more about our privacy policy and cookie policy cookie policy . We use cookies that are essential for our site to work. Please visit our cookie policy for more information. To accept all cookies click 'Accept & close'. - Perl Basics
- Perl - Home
- Perl - Introduction
- Perl - Environment
- Perl - Syntax Overview
- Perl - Data Types
- Perl - Variables
- Perl - Scalars
- Perl - Arrays
- Perl - Hashes
- Perl - IF...ELSE
- Perl - Loops
Perl - Operators- Perl - Date & Time
- Perl - Subroutines
- Perl - References
- Perl - Formats
- Perl - File I/O
- Perl - Directories
- Perl - Error Handling
- Perl - Special Variables
- Perl - Coding Standard
- Perl - Regular Expressions
- Perl - Sending Email
- Perl Advanced
- Perl - Socket Programming
- Perl - Object Oriented
- Perl - Database Access
- Perl - CGI Programming
- Perl - Packages & Modules
- Perl - Process Management
- Perl - Embedded Documentation
- Perl - Functions References
- Perl Useful Resources
- Perl - Questions and Answers
- Perl - Quick Guide
- Perl - Useful Resources
- Perl - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
What is an Operator?Simple answer can be given using the expression 4 + 5 is equal to 9 . Here 4 and 5 are called operands and + is called operator. Perl language supports many operator types, but following is a list of important and most frequently used operators − - Arithmetic Operators
- Equality Operators
- Logical Operators
- Assignment Operators
- Bitwise Operators
Quote-like OperatorsMiscellaneous operators. Lets have a look at all the operators one by one. Perl Arithmetic OperatorsAssume variable $a holds 10 and variable $b holds 20, then following are the Perl arithmatic operators − Show Example Sr.No. | Operator & Description | 1 | Adds values on either side of the operator − $a + $b will give 30 | 2 | Subtracts right hand operand from left hand operand − $a - $b will give -10 | 3 | Multiplies values on either side of the operator − $a * $b will give 200 | 4 | Divides left hand operand by right hand operand − $b / $a will give 2 | 5 | Divides left hand operand by right hand operand and returns remainder − $b % $a will give 0 | 6 | Performs exponential (power) calculation on operators − $a**$b will give 10 to the power 20 | Perl Equality OperatorsThese are also called relational operators. Assume variable $a holds 10 and variable $b holds 20 then, lets check the following numeric equality operators − Sr.No. | Operator & Description | 1 | Checks if the value of two operands are equal or not, if yes then condition becomes true. − ($a == $b) is not true. | 2 | Checks if the value of two operands are equal or not, if values are not equal then condition becomes true. − ($a != $b) is true. | 3 | Checks if the value of two operands are equal or not, and returns -1, 0, or 1 depending on whether the left argument is numerically less than, equal to, or greater than the right argument. − ($a <=> $b) returns -1. | 4 | Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. − ($a > $b) is not true. | 5 | Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. − ($a < $b) is true. | 6 | Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. − ($a >= $b) is not true. | 7 | Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. − ($a <= $b) is true. | Below is a list of equity operators. Assume variable $a holds "abc" and variable $b holds "xyz" then, lets check the following string equality operators − Sr.No. | Operator & Description | 1 | Returns true if the left argument is stringwise less than the right argument. − ($a lt $b) is true. | 2 | Returns true if the left argument is stringwise greater than the right argument. − ($a gt $b) is false. | 3 | Returns true if the left argument is stringwise less than or equal to the right argument. − ($a le $b) is true. | 4 | Returns true if the left argument is stringwise greater than or equal to the right argument. − ($a ge $b) is false. | 5 | Returns true if the left argument is stringwise equal to the right argument. − ($a eq $b) is false. | 6 | Returns true if the left argument is stringwise not equal to the right argument. − ($a ne $b) is true. | 7 | Returns -1, 0, or 1 depending on whether the left argument is stringwise less than, equal to, or greater than the right argument. − ($a cmp $b) is -1. | Perl Assignment OperatorsAssume variable $a holds 10 and variable $b holds 20, then below are the assignment operators available in Perl and their usage − Sr.No. | Operator & Description | 1 | Simple assignment operator, Assigns values from right side operands to left side operand − $c = $a + $b will assigned value of $a + $b into $c | 2 | Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand − $c += $a is equivalent to $c = $c + $a | 3 | Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand − $c -= $a is equivalent to $c = $c - $a | 4 | Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand − $c *= $a is equivalent to $c = $c * $a | 5 | Divide AND assignment operator, It divides left operand with the right operand and assign the result to left operand − $c /= $a is equivalent to $c = $c / $a | 6 | Modulus AND assignment operator, It takes modulus using two operands and assign the result to left operand − $c %= $a is equivalent to $c = $c % a | 7 | Exponent AND assignment operator, Performs exponential (power) calculation on operators and assign value to the left operand − $c **= $a is equivalent to $c = $c ** $a | Perl Bitwise OperatorsBitwise operator works on bits and perform bit by bit operation. Assume if $a = 60; and $b = 13; Now in binary format they will be as follows − $a = 0011 1100 $b = 0000 1101 ----------------- $a&$b = 0000 1100 $a|$b = 0011 1101 $a^$b = 0011 0001 ~$a = 1100 0011 There are following Bitwise operators supported by Perl language, assume if $a = 60; and $b = 13 Sr.No. | Operator & Description | 1 | Binary AND Operator copies a bit to the result if it exists in both operands. − ($a & $b) will give 12 which is 0000 1100 | 2 | Binary OR Operator copies a bit if it exists in eather operand. − ($a | $b) will give 61 which is 0011 1101 | 3 | Binary XOR Operator copies the bit if it is set in one operand but not both. − ($a ^ $b) will give 49 which is 0011 0001 | 4 | Binary Ones Complement Operator is unary and has the efect of 'flipping' bits. − (~$a ) will give -61 which is 1100 0011 in 2's complement form due to a signed binary number. | 5 | Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand. − $a << 2 will give 240 which is 1111 0000 | 6 | Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand. − $a >> 2 will give 15 which is 0000 1111 | Perl Logical OperatorsThere are following logical operators supported by Perl language. Assume variable $a holds true and variable $b holds false then − Sr.No. | Operator & Description | 1 | Called Logical AND operator. If both the operands are true then then condition becomes true. − ($a and $b) is false. | 2 | C-style Logical AND operator copies a bit to the result if it exists in both operands. − ($a && $b) is false. | 3 | Called Logical OR Operator. If any of the two operands are non zero then then condition becomes true. − ($a or $b) is true. | 4 | C-style Logical OR operator copies a bit if it exists in eather operand. − ($a || $b) is true. | 5 | Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false. − not($a and $b) is true. | There are following Quote-like operators supported by Perl language. In the following table, a {} represents any pair of delimiters you choose. Sr.No. | Operator & Description | 1 | Encloses a string with-in single quotes − q{abcd} gives 'abcd' | 2 | Encloses a string with-in double quotes − qq{abcd} gives "abcd" | 3 | Encloses a string with-in invert quotes − qx{abcd} gives `abcd` | There are following miscellaneous operators supported by Perl language. Assume variable a holds 10 and variable b holds 20 then − Sr.No. | Operator & Description | 1 | Binary operator dot (.) concatenates two strings. − If $a = "abc", $b = "def" then $a.$b will give "abcdef" | 2 | The repetition operator x returns a string consisting of the left operand repeated the number of times specified by the right operand. − ('-' x 3) will give ---. | 3 | The range operator .. returns a list of values counting (up by ones) from the left value to the right value − (2..5) will give (2, 3, 4, 5) | 4 | Auto Increment operator increases integer value by one − $a++ will give 11 | 5 | Auto Decrement operator decreases integer value by one − $a-- will give 9 | 6 | The arrow operator is mostly used in dereferencing a method or variable from an object or a class name − $obj->$a is an example to access variable $a from object $obj. | Perl Operators PrecedenceThe following table lists all operators from highest precedence to lowest. Perl Online CompilerWrite, Run & Share Perl code online using OneCompiler's Perl online compiler for free. It's one of the robust, feature-rich online compilers for Perl language, running on the latest version 5.22.1. Getting started with the OneCompiler's Perl compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as Perl and start coding. Taking inputs (stdin)OneCompiler's Perl online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample Perl program which takes name as input and prints hello message with your name. Perl(Practical Extraction and Report Language) is especially desined for text processing by Larry Wall. Key features- Cross-platform
- Efficient for mission critical applications.
- Open-source
- Supports both procedural and object-oriented programming.
- Perl interpreter is embeddable with other systems.
- Loosely typed language
Syntax helpThere is no need to specify the type of the data in Perl as it is loosely typed language. Type | Description | Usage |
---|
Scalar | Scalar is either a number or a string or an address of a variable(reference) | $var | Arrays | Array is an ordered list of scalars, you can access arrays with indexes which starts from 0 | @arr = (1,2,3) | Hash | Hash is an unordered set of key/value pairs | %ul = (1,'foo', 2, 'bar) |
In Perl, there is no need to explicitly declare variables to reserve memory space. When you assign a value to a variable, declaration happens automatically. 1. If family:If, If-else, Nested-Ifs are used when you want to perform a certain set of operations based on conditional expressions. Nested-If-elseThere is no case or switch in perl, instead we use given and when to check the code for multiple conditions. For loop is used to iterate a set of statements based on a condition. While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance. 5. Do-While:Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once. Sub-routinesSub-routines are similar to functions which contains set of statements. Usually sub-routines are written when multiple calls are required to same set of statements which increases re-usuability and modularity. How to define a sub-routineHow to call a sub-routine. - Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
- Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand
- OverflowAI GenAI features for Teams
- OverflowAPI Train & fine-tune LLMs
- Labs The future of collective knowledge sharing
- About the company Visit the blog
Collectives™ on Stack OverflowFind centralized, trusted content and collaborate around the technologies you use most. Q&A for work Connect and share knowledge within a single location that is structured and easy to search. Get early access and see previews of new features. .= operator in perlCan someone explain me what is happening here? I am trying to read a Downloaded-XML file thanks in advance - Specifically: perldoc.pl/perlop#Additive-Operators and perldoc.pl/perlop#Assignment-Operators – Grinnz Commented Dec 12, 2018 at 21:47
The dot ( . ) is the concatenation operator in Perl. Sometimes you want to concatenate text to the same variable. Most binary operators in Perl have an "assignment" version which simplifies code like this. So instead of: You can just write: Syntax like this can be found in pretty much any C-style programming language. In Perl, the concatenation operator has an assignment version. So instead of: So, reversing that logic, your code: Is just a shortcut for: - you beautifully answered my question. Thanks a lot. – Chuda Mainali Commented Dec 13, 2018 at 16:06
Your AnswerReminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more Sign up or log inPost as a guest. Required, but never shown By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy . Not the answer you're looking for? Browse other questions tagged perl or ask your own question .- The Overflow Blog
- This developer tool is 40 years old: can it be improved?
- Unpacking the 2024 Developer Survey results
- Featured on Meta
- We've made changes to our Terms of Service & Privacy Policy - July 2024
- Introducing an accessibility dashboard and some upcoming changes to display...
- Tag hover experiment wrap-up and next steps
Hot Network Questions- If KCI allows MitM attacks, how are ephemeral exchanges an effective mitigation?
- Schengen visa expires during my flight layover
- Is there a pre-defined compiler macro for legacy Microsoft C 5.10 to get the compiler's name and version number?
- Low current continuity checker
- How could ocean liners survive in a major capacity after large jet airliners become common?
- Four Year Old Pushing and Positive Discipline Techniques
- Why did the Black Order leave Heimdall alive?
- Best (safest) order of travel for Russia and the USA (short research trip)
- ULN2803 relay and led together
- How can I pass a constructed image path to \lettrine?
- Generalized Super-Luhn
- Did Einstein say the one-way speed-of-light is "not a fact of nature"?
- A finance broker made me the primary instead of a co-signer
- Is there mutable aliasing in this list of variable references?
- In Europe, are you allowed to enter an intersection on red light in order to allow emergency vehicles to pass?
- Set all numbers greater than "X" bold, for decimal numbers
- What are those small notes below other ones?
- What would "doctor shoes" have looked like in "Man on the Moon"?
- Abrupt increase of evaluation time of MatrixExp
- How can I run a machine language program off the disk drive on an Apple II?
- Why would sperm cells derived from women's stem cells always produce female children?
- Word/phrase for avoiding a task because it has a lot of unknowns
- Stacked Nurikabe
- Should I include MA theses in my phd literature review?
|
IMAGES
COMMENTS
These combined assignment operators can only operate on scalars, whereas the ordinary assignment operator can assign to arrays, hashes, lists and even references.
Perl assignments operators Assignment operators perform expression and assign the result to a variable.
An operator is a character that represents an action, for example + is an arithmetic operator that represents addition. Operators in perl are categorised as following types: 1) Basic Arithmetic Operators. 2) Assignment Operators. 3) Auto-increment and Auto-decrement Operators. 4) Logical Operators.
Assignment Operators Used to assign scalar or array data to a data structure. Operators: = Simple assignment - assigns values from right side operands and operators to left side operand += Addition and assign - add right operand to left operand and assign to left operand -= Substract and assign - substract right operand from left operand and assign to left operand *= Multiply and assign ...
Introduction Perl's set of operators borrows extensively from the C programming language. Perl expands on this by infusing new operators for string functions ( .=, x, eq, ne, etc.). C by contrast delegates its subset of Perl functionality to a library strings.h, and ctype.h, and includes no such functionality by default compilation. Perl also includes a highly flexible Regex engine inspired by ...
Assignment simply set values on the left side of a = to what is on the right side. This works for both strings and numbers in Perl. You can speed an assignment like $a=$a*3; by using a handy shortcut used in C and C++. You can simplify variable=variable operator expression to variable operator=expression.
In this tutorial, you'll learn about Perl operators including numeric operators, string operators, and logical operators.
Perl Assignment Operators PERL Server Side Programming Programming Scripts Assume variable aholds10andvariable a h o l d s 10 a n d v a r i a b l e b holds 20, then below are the assignment operators available in Perl and their usage −
Perl - Assignment Operators Tutorialspoint 3.39M subscribers Subscribed 25 6K views 5 years ago Perl Online Training
Perl - assignment operators example The example below shows the usage of assignment and compound assignment operators: = Assignment operator += Addition AND assignment operator -= Subtraction AND assignment operator *= Multiply AND assignment operator /= Division AND assignment operator %= Modulo AND assignment operator
Perl | Operators | Set - 1. Operators are the main building block of any programming language. Operators allow the programmer to perform different kinds of operations on operands. In Perl, operators symbols will be different for different kind of operands (like scalars and string).
Operators Table 4.3 lists all the Perl operators from highest to lowest precedence and indicates their associativity. Table 4-3. Perl Associativity and Operators, Listed by Precedence Associativity Operators Left Terms … - Selection from Perl in a Nutshell [Book]
Try the following example to understand all the assignment operators available in Perl. Copy and paste the following Perl program in test.pl file and execute this program.
The symbol = is compiled into one of two assignment operators: A list assignment operator ( aassign) is used if the left-hand side (LHS) of a = is some kind of aggregate. A scalar assignment operator ( sassign) is used otherwise.
Assignment operators in programming languages like Perl are fundamental components that simplify assigning values to variables. They are not just limited to the basic assignment but also include a range of compound assignment operators that combine arithmetic, string, and other operations with the assignment.
Perl language supports many operator types, but following is a list of important and most frequently used operators −. Arithmetic Operators. Equality Operators. Logical Operators. Assignment Operators. Bitwise Operators. Logical Operators. Quote-like Operators. Miscellaneous Operators.
Perl Online Compiler Write, Run & Share Perl code online using OneCompiler's Perl online compiler for free. It's one of the robust, feature-rich online compilers for Perl language, running on the latest version 5.22.1. Getting started with the OneCompiler's Perl compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as Perl and start coding.
In Perl, logical values are generally represented by 0 (or sometimes '' or undef) for false and 1 for true. However, to be more specific, any value that is not one of the above three false values is treated as true, and sometimes programmers refer to this distinction using the informal terms "truthy" and "falsy".
perl edited Dec 12, 2018 at 16:56 Micha Wiedenmann 20.5k 22 93 140 asked Dec 12, 2018 at 16:55 Chuda Mainali 13 6 Specifically: perldoc.pl/perlop#Additive-Operators and perldoc.pl/perlop#Assignment-Operators - Grinnz Dec 12, 2018 at 21:47