Lab 8 - Getting Sociable with Perl |
Overview |
In this lab, we'll write the database backend for a very simple social network application. This application will only worry about keeping track of lists of people's friends, where friendship is automatically mutual - if Alice is friends with Bob, then Bob is friends with Alice as well. We'll also review the solution to the lab from last week. |
Last week's lab |
Last week's lab was a (relatively) simple extension of previously-written code that
required you to import a few functions into your new program (using
a require statement, not copy+paste) and then call them in a loop. The
code that you had to write was almost exactly the same as the code in the solution
developed in the first part of the lab, except that it happened in a loop. We'll go
over the solution in lab - if you don't understand something, there are probably
four other people who don't either and would be secretly grateful to you if you
stopped me and asked.
|
Social Networking |
Imagine you want to create a better Facebook (much of which is written in Perl, by the way). The first step would be to create a database that keeps track of users and their friends. We'll write a simple program to demo this database. If you were really creating a better Facebook, you might use the methods you create here as part of a much larger program; in this lab, we'll develop them with modularity in mind. Here is a example of how your program might look when run. In this example, I become friends with my evil twin but then remove the friendship when I realize his sinister secret. jpr@sulu (i211/lab8) % ./socialnet.pl add Jacob Ratkiewicz jpr@sulu (i211/lab8) % ./socialnet.pl add Bocaj Zciweiktar jpr@sulu (i211/lab8) % ./socialnet.pl print Jacob Ratkiewicz has no friends. Bocaj Zciweiktar has no friends. jpr@sulu (i211/lab8) % ./socialnet.pl friend Jacob Ratkiewicz Bocaj Zciweiktar jpr@sulu (i211/lab8) % ./socialnet.pl print Jacob Ratkiewicz is friends with: Bocaj Zciweiktar Bocaj Zciweiktar is friends with: Jacob Ratkiewicz jpr@sulu (i211/lab8) % ./socialnet.pl add Random Dude jpr@sulu (i211/lab8) % ./socialnet.pl friend Jacob Ratkiewicz Random Dude jpr@sulu (i211/lab8) % ./socialnet.pl print Bocaj Zciweiktar is friends with: Jacob Ratkiewicz Jacob Ratkiewicz is friends with: Bocaj Zciweiktar, Random Dude Random Dude is friends with: Jacob Ratkiewicz jpr@sulu (i211/lab8) % ./socialnet.pl unfriend Jacob Ratkiewicz Bocaj Zciweiktar jpr@sulu (i211/lab8) % ./socialnet.pl print Jacob Ratkiewicz is friends with: Random Dude Bocaj Zciweiktar has no friends. Random Dude is friends with: Jacob Ratkiewicz Notice that the program socialnet.pl is being run from the command line
multiple times, but somehow remembers who is friends with who between each run. That
is because it is using a hash tied to a DB_File (really, to
an MLDBM ) to remember friendship relations. That's hint #1.
Hint #2, even more important, is that this is exactly what you need to do in Project
Checkpoint 2.
Do this:
Start writing Your program should recognize the following commands, given on the command line:
You can assume that your users give you valid input. Here are some links that might help:
|
Turn in your assignment |
Strictly speaking, there's only one file in this week's lab, so a tarball isn't really required. However, let's make one anyway. As a reminder, here's the command you can use: jpr@sulu (i211/lab8) $ cd .. jpr@sulu (i211) $ tar czv lab8 > lab8.tar.gz socialnet.pl jpr@sulu (i211) $ You should then download this Okay, that's it! Have a good weekend. |