IT 441: Network Services Administration
Class #08 Exercise

Complete by: 3/22/2018


Log in to users.cs.umb.edu

Simple list printing

perl>  print (1, 2, 3, 4) ;

perl>  print ("1", "2", "3", "4", ".") ;

perl>  print ("1 ", "2 ", "3 ", "4 ", ".") ;

perl>  $a = 35 ;

perl>  $b = 7 ;

perl>  $c = 2 ;

perl>  print ($a, $b, $c) ;

perl>  print ($a, " ", $b, " ", $c) ;

perl>  print ("$a ", "$b ", "$c") ;

perl>  print ('$a ', '$b ', '$c') ;

perl>  print ("$a , $b ", "$c") ;

perl>  print ('$a , $b ', '$c') ;

perl>  print ( 1 + $a , "\n" , $b * $c, "\n" , (1 + $a) / ($b - 1) ) ;

perl>  print ( 1 + $a , '\n' , $b * $c, '\n' , (1 + $a) / ($b - 1) ) ;

perl>  print ( "1 + $a" , "\n" , "$b * $c", "\n" , "(1 + $a) / ($b - 1)" ) ;

perl>  print ( '1 + $a' , "\n" , '$b * $c', "\n" , '(1 + $a) / ($b - 1)' ) ;
(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 list printing

perl>  print (qw/1, 2, 3, 4, 5, 6, 7/) ;

perl>  print (qw[1, 2, 3, 4, 5, 6, 7]) ;

perl>  print qw/1, 2, 3, 4, 5, 6, 7/ ;

perl>  print qw[1, 2, 3, 4, 5, 6, 7] ;

perl>  print (1..7) ;

perl>  print qw/1..7/ ;

perl>  print reverse (1, 2, 3, 4, 5, 6, 7) ;

perl>  print reverse qw/1, 2, 3, 4, 5, 6, 7/ ;

perl>  print (-7..7) ;

perl>  print reverse (-7..7) ;
(Did any of the results seem odd or anomalous?
What do you think accounts for those anomalies?)

Individual elements and list slices

perl>  print (1, 2, 3, 4, 5, 6, 7)[0] ;

perl>  print ( (1, 2, 3, 4, 5, 6, 7)[0] ) ;

perl>  for ($i = 0 ; $i < 7 ; $i++) { print ( (1, 2, 3, 4, 5, 6, 7)[$i] ) ; print "\n"; }

perl>  for ($i = 6 ; $i >= 0 ; $i--) { print ( (1, 2, 3, 4, 5, 6, 7)[$i], "\n" ) ; }

perl>  print ( (1, 2, 3, 4, 5, 6, 7)[0..3] ) ;

perl>  print ( (1, 2, 3, 4, 5, 6, 7)[1..4] ) ;

perl>  print ( (1, 2, 3, 4, 5, 6, 7)[4..1] ) ;

perl>  print ( (qw/1, 2, 3, 4, 5, 6, 7/)[2] ) ;

perl>  print ( (qw/1, 2, 3, 4, 5, 6, 7/)[2..5] ) ;

perl>  print ( qw/1, 2, 3, 4, 5, 6, 7/[2] ) ;

perl>  print ( qw/1, 2, 3, 4, 5, 6, 7/[-1] ) ;

perl>  for ($i = -7 ; $i < 0 ; $i++) { print qw/1, 2, 3, 4, 5, 6, 7/[$i] ; print "\n"; }

perl>  print ( (qw/1, 2, 3, 4, 5, 6, 7/)[-5..-2] ) ;

perl>  for ($i = 0 ; $i < 7 ; $i++) { print ( (reverse(1, 2, 3, 4, 5, 6, 7))[$i] ) ; print "\n"; }
(How many results conformed to your predictions? How many did not
What do you think accounts for those differences?)

End the Perl Session

perl>  exit

End the script session

Use the exit command. You should then have a file called typescript in your current working directory.