Perls Before Swine: The basic Perl filter

  1. Introduction
  2. Perls Before Swine
  3. Smarter scripts

Make sure you’ve downloaded the sample data, and then create the following text file:

#!/usr/bin/perl
while (<>) {
print;
}

Save this file as the filename show. Once you’ve saved it, make sure that it is executable by you. Go to your command line, make sure that your are in the correct folder, and type:

chmod u+x show

On Mac OS X, you can ensure that you are in the correct folder by typing “cd” in the terminal, a space, and then dragging the folder onto your terminal window. Press return, and you will change directory into that folder.

Now, type:

./show show

The script should show you itself. Make sure that songs.txt is in the same directory as your script, and type:

./show songs.txt

The show script should show you all 7,006 lines in the songs.txt file.

  1. Introduction
  2. Perls Before Swine
  3. Smarter scripts