Log in to users.cs.umb.edu
- Log in to a Windows machine
Enter your Unix username as the account name. Then enter your password.- Run the ssh client
Use the values in the table below to connect to users.
ssh configuration parameter value protocol ssh ssh version 2 ssh port 22 host users.cs.umb.edu user name your unix username Authentication method password - Enter your password
A dialog box will appear on the screen into which you must type the password for your Unix account.- Make sure you are in your home directory
cd- Go to your it441 directory
cd it441- Go to your ex directory
cd ex- Create an ex09 directory
mkdir ex09- Go to your ex09 directory
cd ex09- Execute the script command
script- Use your perlsession alias to start the re.pl script.
perlsession(NOTE: If the perlsession alias is not recognized, or if re.pl cannot run, then double-check your Perl configuration, as well as your login shell vs. subshell environments!)Simple array printing
perl> @nums = (1, 2, 3, 4) ; perl> print @nums ; perl> @nums2 = ("1 ", "2 ", "3 ", "4.") ; perl> print @nums2 ; perl> $a = 35 ; perl> $b = 7 ; perl> $c = 2 ; perl> @nums3 = ($a, $b, $c) ; perl> print @nums3 ; perl> print join (" ", @nums3) ; perl> print join (" ", @nums3) . "."; perl> @nums4 = ("$a", '$b', "$c") ; perl> print @nums4 ; perl> print join (", ", @nums4) ; perl> print join (', ', @nums4) . '!' ; perl> @nums5 = ( 1 + $a , $b * $c, (1 + $a) / ($b - 1) ) ; perl> print @nums5 ; perl> print join ("\n", @nums5) ; perl> print join ('\n', @nums5) ;(Think about the variations in output when lines of code looked fairly similar, with only slight differences...
What do you think accounts for those differences?)Other array printing
perl> @nums = qw/1, 2, 3, 4, 5, 6, 7/ ; perl> print @nums ; perl> @nums2 = qw/1 2 3 4 5 6 7/ ; perl> print @nums2 ; perl> print join (" " , @nums2) ; perl> print join (" " , @nums2) . "..." ; perl> foreach $num (@nums2) { print "$num\n" ; } perl> foreach $num (@nums2) { print '$num\n' ; } perl> @nums3 = (1..7) ; perl> print join (" " , @nums3) . "..." ; perl> foreach $num (@nums3) { print "$num\n" ; } perl> print join (" " , (reverse @nums3)) . "!!!" ; perl> foreach $num (reverse @nums3) { print "$num...\n" ; }(Did any of the results seem odd or anomalous?
What do you think accounts for those anomalies?)Individual elements and array slices
perl> @nums = (1..10) ; perl> print $nums[0] ; perl> for ($i = 0 ; $i < 10 ; $i++) { print $nums[$i] ; print "\n"; } perl> for ($i = 9 ; $i >= 0 ; $i--) { print ( $nums[$i], "\n" ) ; } perl> print ( @nums[0..3] ) ; perl> print ( @nums[1..4] ) ; perl> print ( @nums[4..1] ) ; perl> print ( reverse @nums[1..4] ) ; perl> @nums2 = @nums[3..8] ; perl> print join (" " , @nums2) . "..." ; perl> foreach $num (@nums2) { print "$num\n" ; } perl> @nums3 = reverse @nums2 ; perl> print join (" " , @nums3) . "..." ; perl> foreach $num (@nums3) { print "$num\n" ; } perl> $nums[0] = 19; perl> $nums[3] = -11; perl> $nums[7] = "foobar"; perl> foreach $value (@nums) { print "$value\n" ; }(How many results conformed to your predictions? How many did not?
What do you think accounts for those differences?)Other array operations
perl> $len = scalar @nums ; perl> print 'The length of @nums is: ' . $len ; perl> @nums4 = (1..10) ; perl> while ((scalar @nums4) > 0) { print shift @nums4 ; print "\n" ; } perl> print @nums4; perl> @nums5 = (1..10) ; perl> while ((scalar @nums5) > 0) { print pop @nums5 ; print "\n" ; } perl> print @nums5;(How many results conformed to your predictions? How many did not?
What do you think accounts for those differences?
What do you think "scalar" does with the array @nums?)End the Perl Session
perl> exitEnd the script session
Use the exit command. You should then have a file called typescript in your current working directory.