Perl Conti.....

From DrugPedia: A Wikipedia for Drug discovery

(Difference between revisions)
Jump to: navigation, search
(New page: '''Arithmetic Operators:''' Arithmetic operators are symbols used to execute general arithmetic procedures including: addition (+), subtraction (-), multiplication (*), and division (/). ...)
Line 35: Line 35:
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.
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.
-
==, eq   5 == 5
+
<h2>Relational</h2>
 +
<table CELLSPACING="0" BORDER="1">
 +
<tr><td><b>Operator</b></td><td><b>Example</b></td><td><b>Defined</b></td><td><b>Result</b></td></tr>
 +
<tr><td>==,<font color='red'>eq</font></td><td>5 == 5<br />5 eq 5</td><td>Test: Is 5 equal to 5?</td><td>True</td></tr>
 +
<tr><td>!=,<font color='red'>ne</font></td><td>7 != 2<br />7 ne 2</td><td>Test: Is 7 not equal to 2?</td><td>True</td></tr>
-
5 eq 5   Test: Is 5 equal to 5? True
+
<tr><td>&lt;,<font color='red'>lt</font></td><td>7 &lt; 4<br />7 lt 4</td><td>Test: Is 7 less than 4?</td><td>False</td></tr>
 +
<tr><td>&gt;,<font color='red'>gt</font></td><td>7 &gt; 4<br />7 gt 4</td><td>Test: Is 7 greater than 4?</td><td>True</td></tr>
 +
 
 +
<tr><td>&lt;=,<font color='red'>le</font></td><td>7 &lt;= 11<br />7 le 11</td><td>Test: Is 7 less than or equal to 11?</td><td>True</td></tr>
 +
<tr><td>&gt;=,<font color='red'>ge</font></td><td>7 &gt;= 11<br />7 ge 11</td><td>Test: Is 7 greater than or equal to 11?</td><td>False</td></tr></table>
 +
 
 +
<h2>Logical</h2>
 +
 
 +
<table CELLSPACING="0" BORDER="1">
 +
<tr><td><b>Operator</b></td><td><b>Defined</b></td><td><b>Example</b></td></tr>
 +
<tr><td>&&,<font color='red'>and</font></td><td>Associates two variables using AND</td><td>if (($x && $y) == 5)...</td></tr>
 +
<tr><td>||,<font color='red'>or</font></td><td>Associates two variables using OR</td><td>if (($x || $y) == 5)...</td></tr></table>
 +
 
 +
<p>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.</p>
 +
 
 +
'''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.
 +
 
 +
<nowiki>#TWO STRINGS TO BE ADDED</nowiki><br />
 +
$string1 = "Hello,";<br />
 +
$string2 = " World";
 +
 
 +
<nowiki>#ADD TWO STRINGS TOGETHER</nowiki><br /.
 +
<nowiki>$string3 = "$myvariable + $Myvariable";</nowiki>
 +
 
 +
print $string3;<br />
 +
Output: Hello, +  World

Revision as of 06:12, 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

OperatorExampleDefinedResult
==,eq5 == 5
5 eq 5
Test: Is 5 equal to 5?True
!=,ne7 != 2
7 ne 2
Test: Is 7 not equal to 2?True
<,lt7 < 4
7 lt 4
Test: Is 7 less than 4?False
>,gt7 > 4
7 gt 4
Test: Is 7 greater than 4?True
<=,le7 <= 11
7 le 11
Test: Is 7 less than or equal to 11?True
>=,ge7 >= 11
7 ge 11
Test: Is 7 greater than or equal to 11?False

Logical

OperatorDefinedExample
&&,andAssociates two variables using ANDif (($x && $y) == 5)...
||,orAssociates two variables using ORif (($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