Class 27 review (07/18/2002)

VIP: Bonus Points, 5 pts possible.
     Note that in PERL you can either write:

     if ($str eq "UNI") { print "Go UNI Panthers!"; }

           or write 

     print "Go UNI Panthers!" if ($str eq "UNI");
  1. Unique movies version one.

  2. Unique movies version two. Includes sorting.
    @uniqueFilms = sort keys %films;
        
  3. Unique movies version three. Includes counting number of quotes for each movie! Also detects and prints record number in the data base file of the 3 different problem records (with no movie name).
       print "No movie name in record $n, check it!\n" if ($movieName eq "");
       next if ($movieName eq "");
    
       if ( $films{$movieName} )
       {
          $films{ $movieName }++;
       }
       else
       {
          $films{ $movieName } = 1;
       }
    
  4. Note the following code segments in PERL and how they can be simplified and shortened. Swapping values from one variable to another using Scalar variables, or using array slicing.
    
    
        for ($i = 0; $i < @a; $i++)      foreach (@a)
        {                                {
           print "\n  $_";                  print "\n $a[$i];
        }                                }
    
        $temp = $x;                      ($x, $y) = ($y, $x);
        $x = $y;
        $y = $temp;
    
        $temp = $a[2];                   @a[2, 3] = @a[3, 3];
        $a[2] = $a[3];
        $a[3] = $temp;