
- 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
- Who is Who
Perl Operators Precedence Example
The following table lists all operators from highest precedence to lowest.
left terms and list operators (leftward) left -> nonassoc ++ -- right ** right ! ~ \ and unary + and - left =~ !~ left * / % x left + - . left << >> nonassoc named unary operators nonassoc < > <= >= lt gt le ge nonassoc == != <=> eq ne cmp ~~ left & left | ^ left && left || // nonassoc .. ... right ?: right = += -= *= etc. left , => nonassoc list operators (rightward) right not left and left or xor
Example
Try the following example to understand all the perl operators precedence in Perl. Copy and paste the following Perl program in test.pl file and execute this program.
#!/usr/local/bin/perl $a = 20; $b = 10; $c = 15; $d = 5; $e; print "Value of \$a = $a, \$b = $b, \$c = $c and \$d = $d\n"; $e = ($a + $b) * $c / $d; print "Value of (\$a + \$b) * \$c / \$d is = $e\n"; $e = (($a + $b) * $c )/ $d; print "Value of ((\$a + \$b) * \$c) / \$d is = $e\n"; $e = ($a + $b) * ($c / $d); print "Value of (\$a + \$b) * (\$c / \$d ) is = $e\n"; $e = $a + ($b * $c ) / $d; print "Value of \$a + (\$b * \$c )/ \$d is = $e\n";
When the above code is executed, it produces the following result −
Value of $a = 20, $b = 10, $c = 15 and $d = 5 Value of ($a + $b) * $c / $d is = 90 Value of (($a + $b) * $c) / $d is = 90 Value of ($a + $b) * ($c / $d ) is = 90 Value of $a + ($b * $c )/ $d is = 50
perl_operators.htm
Advertisements