Basic HTML version of Foils prepared Sept 20 97

Foil 12 Operators for Numbers and Strings III --
Binary Assignment

From Tutorial on PERL Computational Science for Information Age Course CPS616 -- Sept 20 97. by Geoffrey C. Fox,Nancy McCracken,Tom Scavo


Assignments are $Next_Course = "CPS615";
$Funding = $Funding + $Contract;
For numeric quantities, the latter can be written as
$Funding += $Contract;
Similarly we can write for strings:
$Name= "Geoffrey"; $Name .= " Fox" # Sets $Name to "Geoffrey Fox"
Example: $A = 6; $B = ($A +=2); # sets $A = $B = 8
Auto-increment and auto-decrememt as in C
  • $a = $a + 1; $a +=1; and ++$a; # are the same and increment $a by 1
++ and -- are both allowed and can be used BEFORE (prefix) or AFTER (suffix) variable (operand). Both forms change operand in same way but in suffix form result used in expression is value BEFORE variable incremented.
  • $a=3; $b = (++$a) # sets $a and $b to 4
  • $a=3; $b = ($a++) # sets $a to 4 and $b to 3



© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sun Sep 21 1997