Follow

Operators

Notes on order of evaluation

The expression 1+2*10 is not the same as (1+2)*10. The first evaluates to 21, the second to 30.
This is because the order of the evaluation depends on the brackets. Expressions obey the BODMAS order of evaluation. Everything within brackets is evaluated first. Then division, multiplication, addition and subtraction. If in doubt, but brackets around the parts of the expression that logically should be evaluated first.


Operators

 Operator  Description  Example
+ Plus. Adds two values together $income1+$income2
- Subtract 2017 - $year_of_birth
/ Divide $yearly_wage/52
* Multiply $weekly_wage*52
> Boolean greater than $age>17
>= Boolean greater than or equal to $age>=18
< Boolean less than $age<66
<= Boolean less than or equal to $age<=65
or Boolean OR $multiple_choice1 or $multiple_choice2
and Boolean AND $nsw_resident and $male
! Boolean NOT !($user_comments)
== Boolean Is equal – numbers only $year_of_birth ==1967
!= Boolean Not equal $number_of_visits !=0
eq Boolean is equal – strings only $state eq 'nsw'
ne Boolean not equal – strings only $state ne 'nsw'
lc Convert string to lowercase lc($state)
uc Convert string to uppercase uc($state)
. Join two strings '(02) '.$telephone_number
=~/pattern/ Boolean Pattern match using 'regular expressions'. Complex but powerful. =~/^[0-9]+$/
if/elsif/else A conditional if-then-else statement, used when a specific output logic is required If ($pcode eq '2026') {'bondi'}
elsif($pcode eq '2021') {'paddington'}
else {'unknown suburb'}

 

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Article is closed for comments.