Class 2

Send programs and assignments to
gogarten@uconn.edu

Grades: based on homework assignments

Check for problems (compare class 1):

To run PERL script:

perl myprogram.pl

In unix
   chmod 755 *.pl
or

   chmod a+x *.pl
turns the files with extension into pl into executables.
Then
   ./myprogram.pl

executes the program.

DON'T RUN THINGS ON THE MASTER NODE ! (At least not things that take longer than a second)

qrsh

or
ssh node010

Check notes for class1 regarding student projects

Old Assignments:

Name the attachments so that they have .pl as extension (then my mail program reconizes them as perl scripts and I can execute them directly in a terminal window).
Don't use last year's sample programs as a study guide!
Don't give up on use strict -- missing ";" are easy to identify, but keeping track of variables created somewhere along a line is more difficult.
Sample Programs are at ex1-1, ex1-3, ex2-1, ex 2-2, ex2-2mod, ex2-3
Discuss modules
New things - annotated example

Numerical Operators:

Operator Associativity Description
** right exponentiation
*, /, % left multiplication, division, modulus
+, - left addition, subtraction
+=,-=,*=    
++,-- none autoincrement/decrement

Examples

my $x = 5 * 2 + 3; # $x is 13
my $y = 2 * $x / 4; # $y is 6.5
my $z = (2 ** 6) ** 2; # $z is 4096
my $a = ($z - 96) * 2; # $a is 8000
my $b = $x % 5; # 3, 13 modulo 5
my $d = $b++; #$b is 4, $d is 3
$d = ++$b; #$b and $d are both 5

Script is here

Binary Assignment Operators
(=     **=     +=     *=      .= )
(if you want to ask is something equal to, you need to use ==
see below)

my $a = $a + 5; # without the binary assignment operator
$a += 5; # with the binary assignment operator

my $b = $b * 3; # without the binary assignment operator
$b *= 3; # with the binary assignment operator

my $str
$str = $str . " "; # append a space to $str
$str .= " 1"; # same thing with assignment operator

$a = 3;
$b = ($a += 4); # $a and $b are both now 7

$a=2;
$a **= 3; # with the binary assignment operator
$a=2;
$a = $a** 3;# withou the binary assignment operator

Script here

Numeric and String Comparison Operators:

 

Comparison

Numeric

String

Equal

==

eq

Not equal

!=

ne

Less than

<

lt

Greater than

>

gt

Less than or equal to

<=

le

Greater than or equal to

>=

ge

 

 

 

 

 

 

logical AND in perl: &&
logical or in perl: ||

 

New Assignments:

E) For the following array declaration

@myArray = ('A', 'B', 'C', 'D', 'E');

what is the value of the following expressions:

$#myArray
length(@myArray)
$myArray[1]
$n=@myArray
reverse (@myArray)