Operators. Perl has MANY operators. –Covered in Chapter 3 of Prog.Perl Most operators have numeric and string version –remember Perl will convert variable.

Slides:



Advertisements
Similar presentations
IF statement (i) Single statement. IF ( logical expression ) statement Example: read(*,*) a if (a. lt. 0) a = -a write(*,*) a Or read(*,*) a if (a < 0)
Advertisements

Operators and Expressions Operators are symbols that produce a result based on some rules. Examples: +, -, =, > and
CSET4100 – Fall 2009 Perl Introduction Scalar Data, Operators & Control Blocks Acknowledgements: Slides adapted from NYU Computer Science course on UNIX.
Scalar Variables Start the file with: #! /usr/bin/perl –w No spaces or newlines before the the #! “#!” is sometimes called a “shebang”. It is a signal.
All the Operators. Precedence An operator with higher precedence is done earlier (prededes) one with lower precedence –A higher precedence is indicated.
All the Operators. Precedence An operator with higher precedence is done earlier (prededes) one with lower precedence –A higher precedence is indicated.
More on Numerical Computation CS-2301 B-term More on Numerical Computation CS-2301, System Programming for Non-majors (Slides include materials from.
Bash, part 2 Prof. Chris GauthierDickey COMP Unix Tools.
CS 3850 Lecture 5 Operators. 5.1 Binary Arithmetic Operators Binary arithmetic operators operate on two operands. Register and net (wire) operands are.
0 Chap. 2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations Imperative Programming, B. Hirsbrunner,
More about Numerical Computation CS-2301, B-Term More about Numerical Computation CS-2301, System Programming for Non-Majors (Slides include materials.
JavaScript, Third Edition
1 Expressions, Operators Expressions Operators and Precedence Reading for this class: L&L, 2.4.
0 Chap. 2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations System-oriented Programming, B. Hirsbrunner,
CSCI 130 Chapter 4 Statements, Expressions, and Operators.
Expressions & Assignments One of the original intentions of computer programs was the evaluation of mathematical expressions –languages would inherit much.
Chapter 4: Operators Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills /1436.
Intro to Programming Problem 1: Computers have to be told exactly what do to. Problem 2: Computers only understand “Machine language”. Problem 3: Machine.
Expressions creating information. topics  operators: precedence, associativity, parentheses, overloading  operands: side-effects, coercion  arithmetic,
OperatorstMyn1 Operators The sequence in which different operators in an expression are executed is determined by the precedence of the operators. Operators.
CHAPTER:8 OPERATORS AND EXPRESSION IN C++ Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 3: Data Types and Operators JavaScript - Introductory.
Operators Using Java operators An operator takes one or more arguments and produces a new value. All operators produce a value from their.
Perl Practical(?)‏ Extraction and Report Language.
CSI 3120, Expressions and assignment, page 1 Expressions and assignment Points for discussion Arithmetic expressions Overloading Logical expressions Assignment.
C Programming Lecture 6 : Operators Lecture notes : courtesy of Ohio Supercomputing Center, and Prof. Woo and Prof. Chang.
C++ Basics Tutorial 6 Operators. What are going to see today? Assignment operator(=) Arithmetic operators(+,-,*,/,%) Compound assignment(+=,-=,*=……..)
Perl Language Yize Chen CS354. History Perl was designed by Larry Wall in 1987 as a text processing language Perl has revised several times and becomes.
Operators Precedence - Operators with the highest precedence will be executed first. Page 54 of the book and Appendix B list C's operator precedence. Parenthesis.
15-Nov-15 All the Operators. operators.ppt 2 Precedence An operator with higher precedence is done earlier (precedes) one with lower precedence A higher.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607 Office Hours – Tuesday and.
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
CIVIL AND GEOMATIC ENGINEERING FT Okyere. CIV 257- COMPUTER PROGRAMMING Lecture 3.
Expressions and Operators in C. Expressions and Operators Examples: 3 + 5; x; x=0; x=x+1; printf("%d",x); Two types: – Function calls – The expressions.
Operators & Expressions
OperatorstMyn1 Operators An operator is something that you feed with one or more values (or expressions, in programming jargon) which yields another value.
Operators.
0 Chap.2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations 2.5Arithmetic Operators 2.6Relational.
ECE 103 Engineering Programming Chapter 4 Operators Herbert G. Mayer, PSU CS Status 6/19/2015 Initial content copied verbatim from ECE 103 material developed.
Expression and Operator. Expressions and Operators u Examples: 3 + 5; x; x=0; x=x+1; printf("%d",x); u Two types: –Function calls –The expressions formed.
Operators A binary operator combines two values to get one result: x OP y where OP is any binary operators such as +, -, *, /, ==, !=, >, &&, or even =.
 Array ◦ Single & Multi-dimensional  Java Operators ◦ Assignment ◦ Arithmetic ◦ Relational ◦ Logical ◦ Bitwise & other.
Operators. Perl has MANY operators. –Covered in Chapter 3 of Camel –perldoc perlop Many operators have numeric and string version –remember Perl will.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
Rational Expressions relational operators logical operators order of precedence.
ECE 103 Engineering Programming Chapter 4 Operators Herbert G. Mayer, PSU Status 6/10/2016 Initial content copied verbatim from ECE 103 material developed.
CSE 220 – C Programming Expressions.
University of Central Florida COP 3330 Object Oriented Programming
Operators Operators are symbols such as + (addition), - (subtraction), and * (multiplication). Operators do something with values. $foo = 25; $foo – 15;
University of Central Florida COP 3330 Object Oriented Programming
Variable Declaration, Data types, Expressions
Operators and Expressions
Control Structures: if Conditional
All the Operators 22-Nov-18.
Context.
All the Operators 4-Dec-18.
Chapter-3 Operators.
Introduction to Programming – 4 Operators
All the Operators 6-Apr-19.
All the Operators 13-Apr-19.
Herbert G. Mayer, PSU CS Status 7/19/2015
Chapter 4: Expression and Operator
The Selection Structure
OPERATORS AND EXPRESSIONS IN C++
ENERGY 211 / CME 211 Lecture 5 October 1, 2008.
DATA TYPES AND OPERATIONS
INTRODUCTION to PERL PART 1.
ICS 101 Lab 3 Hossain Arif ICS Dept
Karan Thaker CS 265 Section 001
Presentation transcript:

Operators

Perl has MANY operators. –Covered in Chapter 3 of Prog.Perl Most operators have numeric and string version –remember Perl will convert variable type for you. Go through them in decreasing precedence

Increment/Decrement ++ and --. Postfix and Prefix work as in C. ++ is “magical”. –if value is purely numeric, works as expected –if string value, or ever used as string, magic happens –‘99’++  ‘100’ –‘a9’++  ‘b0’ –‘Az’++  ‘Ba’ –‘zz’++  ‘aaa’ Try it, see what happens.

Exponentiation **  Exponentiation. Calls C’s pow() function –works on floating points –2**3 == pow(2, 3) == “2 to the power of 3” == 8 –NOTE: higher precedence than negation -2**4  -(2**4)  -16

Unary Operators ! – logical negation –0, “0”, “”, undef  all false –anything else  true - – arithmetic negation (if numeric) –if non-numeric, ‘negates’ the string –ex: $foo = “-abc”; $bar = -$foo; –$bar gets value “+abc”; ~ – bitwise negation

Multiplicative / -- Division. Done in floating point. % -- Modulus. Same as in C. * -- Numeric multiplication x -- String multiplication (aka repetition). –123 * 3  369 –123 x 3  ‘ ’ (scalar context) –(123) x 3  (123, 123, 123) (list context)

Additive + – normal addition - – normal subtraction. – string concatenation –$var1 = “hello”; $var2 = “world”; –$var3 = $var1. $var2; $var3 contains “helloworld” –$var3 = “$var1 $var2”; $var3 contains “hello world”

Shift operators > - work as in C. 1 << 4  >> 4  2

Relational Operators NumericStringMeaning >gt Greater Than >=ge Greater Than or Equal <lt Less Than <=le Less Than or Equal

Equality Operators NumericStringMeaning ==eq Equal to !=ne not equal to cmp comparison -1 if left < right 0 if left == right 1 if left > right

Bitwise Operators & -- AND. | -- OR ^ -- XOR –& has higher precedence if either value numeric: –convert to integer, –bitwise comparison on integers if both values strings: –bitwise comparison on corresponding bits from the two strings

“C-Style” Logical Operators && - AND || - OR –&& has higher precedence operate in short-circuit evaluation –ie, evaluate only what’s needed –creates this common Perl line: open (FILE, “file.txt”) || die “Can’t open file.txt”; return last value evaluated, not 0 or 1.

Conditional Operator ?: -- Trinary operator in C. like an if-else statement, but it’s an expression –$a = $ok ? $b : $c; –if $ok is true, $a = $b. if $ok is false, $a = $c

Assignment operators =, **=, *=, /=, %=, x=, +=, -=,.=, &=, |=, ^=, >=, &&=, ||= In all cases, all assignments of form TARGET OP= EXPR evaluate as: TARGET = TARGET OP EXPR

Comma Operator Scalar context: –evaluate each list element, left to right. Throw away all but last value. –$a = (fctn(), fctn2(), fctn3()); fctn() and fctn2() called, $a gets value of fctn3() Array context: –list separator, as in array assignment = fctn(), fctn2(), gets return values of all three functions

Logical and, or, not, xor Functionally equivalent to &&, ||, ! BUT, a lower precedence. $xyz = $x || $y || $z; $xyz = $x or $y or $z; What’s the difference?

Incomplete list ALL operators found in Chapter 3 of PP. some skipped over, we’ll talk about them later. (arrow, file test, range)