Perl Conti.....
From DrugPedia: A Wikipedia for Drug discovery
Line 68: | Line 68: | ||
print $string3;<br /> | print $string3;<br /> | ||
- | Output: Hello, + World | + | Output: Hello, + World<br /> |
+ | '''PERL - Array Variables''' | ||
+ | |||
+ | Arrays are complex variables that store list style data types. Each object of the list is termed an element and elements can either be a string, a number, or any type of scalar data including another variable.Place an array into a PERL script, using the at symbol (@). | ||
+ | <br /> |
Revision as of 06:17, 8 September 2008
Arithmetic Operators:
Arithmetic operators are symbols used to execute general arithmetic procedures including: addition (+), subtraction (-), multiplication (*), and division (/).
7 + 7 = 14 Addition
7 - 7 = 0 Subtraction
7 * 7 = 49 Multiplication
7 / 7 = 1 Division
7 ** 7 = 823543 Exponents
7 % 7 = 0 Modulus
PERL - Assignment Operators
Addition ($x += 10)
Subtraction ($x -= 10)
Multiplication ($x *= 10)
Division ($x /= 10)
Modulus ($x %= 10)
Exponent ($x **= 10)
PERL - Logical & Relational Operators
Relationship operators compare one variable to another. (5 < 12) They are used to compare equality or inequality of two or more variables, be it a string or numeric data.
Logical operators state and/or relationships. Meaning, you can take two variables and test an either or conditional. Logical operators are used later on in conditionals and loops. For now, just be able to recognize them in the upcoming examples.
Relational
Operator | Example | Defined | Result |
==,eq | 5 == 5 5 eq 5 | Test: Is 5 equal to 5? | True |
!=,ne | 7 != 2 7 ne 2 | Test: Is 7 not equal to 2? | True |
<,lt | 7 < 4 7 lt 4 | Test: Is 7 less than 4? | False |
>,gt | 7 > 4 7 gt 4 | Test: Is 7 greater than 4? | True |
<=,le | 7 <= 11 7 le 11 | Test: Is 7 less than or equal to 11? | True |
>=,ge | 7 >= 11 7 ge 11 | Test: Is 7 greater than or equal to 11? | False |
Logical
Operator | Defined | Example |
&&,and | Associates two variables using AND | if (($x && $y) == 5)... |
||,or | Associates two variables using OR | if (($x || $y) == 5)... |
Please note that you must use each different operator depending of whether or not you are comparing strings or numbers. In the table above, the black operators are for numbers and the red ones are for strings.
PERL - Variables + Operators
Variables can be used with mathematical formulas using PERL Operators discussed in a previous lesson. Also, note that variables are case sensitive. "$myvariable," "$MYvariable," and "$Myvariable" can all be assigned different values due to case sensitivity. Numbers of course can be added, subtracted, or multiplied using operators. Strings as shown in the example below can also be used with operators.
#TWO STRINGS TO BE ADDED
$string1 = "Hello,";
$string2 = " World";
#ADD TWO STRINGS TOGETHER<br /. $string3 = "$myvariable + $Myvariable";
print $string3;
Output: Hello, + World
PERL - Array Variables
Arrays are complex variables that store list style data types. Each object of the list is termed an element and elements can either be a string, a number, or any type of scalar data including another variable.Place an array into a PERL script, using the at symbol (@).