Lab 6 - Regular Expression Practice

Overview
Today, we'll be getting more practice with regular expressions, and start our work with functions.

 

Regular expression practice
Imagine you have a set of track listings for albums. The track listings look like this:
Time        File size   Name
3:19.70     35268284    Pink Floyd - The Wall - In the Flesh.flac
2:29.65     26436524    Pink Floyd - The Wall - The Thin Ice.flac
3:09.72     33508988    Pink Floyd - The Wall - Another Brick in the Wall part 1.flac
1:51.30     19651004    Pink Floyd - The Wall - The Happiest Days of Our Lives.flac
3:59.70     42324284    Pink Floyd - The Wall - Another Brick in the Wall part 2.flac
5:36.48     59383340    Pink Floyd - The Wall - Mother.flac
2:48.20     29682284    Pink Floyd - The Wall - Goodbye Blue Sky.flac
2:08.15     22614524    Pink Floyd - The Wall - Empty Spaces.flac
3:30.65     37196924    Pink Floyd - The Wall - Young Lust.flac
3:37.55     38408204    Pink Floyd - The Wall - One of My Turns.flac
4:17.00     45334844    Pink Floyd - The Wall - Don't Leave Me Now.flac
1:14.72     13222988    Pink Floyd - The Wall - Another Brick in the Wall part 3.flac
1:17.10     13606364    Pink Floyd - The Wall - Goodbye Cruel World.flac

Write a program that will read a track listing like this from a file, and output the total runtime and total size (in bytes). For your reference, the correct answers here are 39:19.92 and 416638556 B.

Do this:
Write music.pl. This is a complicated problem, so don't underestimate it. In English, your program might work like this:
  1. Read the file in, one line at a time.
  2. For each line:
    1. Split the line on whitespace
    2. Get the time, and split it into minutes, seconds, and hundreths.
    3. Add the minutes, seconds, and hundreths to the total. Remember to "roll over" each field appropriately (e.g. hundreths should range from 0-99, but seconds can only go from 0-59).
    4. Get the size, and add it to the total.

DO NOT try to write this program all at once; use incremental development strategies.

 

Subroutine practice
Hre, our goal is to rewrite the above program to use a few functions. We'll also add some functionality. The following is potential skeleton for your program:

#!/usr/bin/perl -w
use strict;

### define functions here...

# open file here
my @lines = # read file into @lines

my $total_runtime = determine_total_runtime( @lines );
my $total_size = determine_total_size( @lines );
my $longest_running_song = determine_longest_running_song(@lines);

#print out the above

The determine_total_runtime and determine_total_size can re-use materials from the first part of this lab. determine_longest_running_song should print out the name of the song with the longest runtime; it is up to you to figure out how this is done! Keep in mind that the name of a song can include whitespace, but the track listing will have only three columns..

Do this:
Create submusic.pl.

 

Turn in your assignment
As usual, let's make a tarball of your assignment files (make sure they are ALL in the lab6 directory!) For this lab, you should have the following files:
  • music.pl
  • submusic.pl
As a reminder, here's the command you can use:

jpr@sulu (i211/lab6) $ cd ..
jpr@sulu (i211) $ tar czv lab6 > lab6.tar.gz
music.pl
submusic.pl
jpr@sulu (i211) $

You should then download this lab6.tar.gz file and upload to the Lab 6 assignment on Oncourse. Make sure you press "submit" and "finish" enough times to actually upload your file. We will take off points for incorrect submissions, even if you really finished the lab on time.

Okay, that's it! Have a good weekend.

Thanks to Jacob Ratkiewicz for lab content, Sid Stamm for CSS stylesheets, and Rob Signorelli for original syntax-highlighting JavaScript.