Lesson 1 - Getting Started

Perl is great,
Perl is fun;
If you build it,
It should run
.



Your task, should you choose to accept it, is to install Perl (if necessary), run a test program, edit the program, and run it again.  The instructions below differ according to whether you are using a Mac or a Windows PC, and whether you will be using Linux to run your Perl scripts.

Windows users

Windows users that don't want to use Linux should complete these tasks:
  1. Install Perl.  I recommend the ActiveState version.  You can download it here.  Make sure that you reboot your machine afterwards so that your PATH will be set correctly.

  2. Create a directory, C:\PerlStuff , in which to keep all your Perl scripts.

  3. Download the Perl script localtime.txt to C:\PerlStuff.  (Right-click the link on the left, chose “Save Target As,” and save the file to your C:\PerlStuff folder.)

  4. Now, run the Perl script.  You’ll first want to start up a “DOS box.”  You can do this by clicking the Start button, then Programs, then Accessories , then MS-DOS Prompt or Command Prompt.  After you have your DOS box, type this:
    c:
    cd \PerlStuff
    perl localtime.txt

    If it doesn’t work, maybe you forgot to reboot after installing Perl?  Reboot and try again.  If it still doesn’t work, try typing “\perl\bin\perl localtime.txt”.  If it still doesn’t work then stop by my office in Dr. McClelland’s lab or give me a call at extension 299.

  5. Next, edit localtime.txt with Wordpad.  You can either run Wordpad from the Start menu, or you can type “write localtime.txt” from your DOS box.  Then change localtime.txt to look like this:
    #!/usr/bin/perl

    for ($i = 0; $i < 5; $i++) {
    @foo = localtime(time);
    ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = @foo;
    printf "%02d/%02d/%04d %02d:%02d:%02d\n",
    $mon + 1, $mday, $year + 1900,
    $hour, $min, $sec;
    sleep(1);
    }
  6. Run the program again. Did it work? Yes? Then you’re done for now.

Linux users - minimalistic instructions

Brave souls, please complete the following tasks:
  1. Log on to linux by clicking here. (You may also want to drag this link to your desktop for future use.)  If the link doesn’t work, then you must be a Mac user.  You’ll need to install a telnet program.  You can find a bunch of them here.  After you’ve installed telnet, use it to connect to the host “10.0.1.200”.

  2. Your telnet session will prompt you with “login:” for your username. Type in your username. (Your linux username is the same as your email username, which is probably your first initial and last name.) Next it will ask for your password.  Remember that your initial password is “change_me”.

  3. Once you’ve logged in, change your password with the passwd command.  Just type “passwd” at the linux prompt.  It will ask for your old password (change_me), and your new password.  Make sure to remember your new password.

  4. Now, copy the sample Perl script localtime.txt to your linux home directory.  The easiest way to do this is to type
    cp ~flong/public_html/perl/lesson1/localtime.txt .
    (In Linux and Unix, “~flong” means “flong’s home direcotry,” and “.” means “your current directory,” which in this case is your home directory.)

  5. Now run the program with
    perl localtime.txt
  6. Next, type “pico localtime.txt” and change the text to look like this:
    #!/usr/bin/perl
    for ($i = 0; $i < 5; $i++) {
    @foo = localtime(time);
    ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = @foo;
    printf "%02d/%02d/%04d %02d:%02d:%02d\n",
    $mon + 1, $mday, $year + 1900,
    $hour, $min, $sec;
    sleep(1);
    }
    Then type Control-O and save the file to “localtime5.txt”. Finally, exit pico with Control-X.

  7. Now run the new script with the following command: “perl localtime5.txt”.  If it worked, you’re done.

Other stuff for Linux users

Transfering files — Windows users

You can access your Linux home directory from Windows by tryping “\\escalade\<username>” in Windows Explorer or Internet Explorer, where <username> is your username.  Now it's time for you to practice: Download localtime.txt to your Windows workstation, and then transfer it to your Linux home directory.

Transfering files — Mac users

Try this SSH-based program first: RBrowserLite. If that doesn’t work, there are a bunch of FTP programs here.  If all else fails, there's always copy-and-paste (see below).

Transfering files — Copy and Paste

Here's an example of how you could use copy-and-paste to transfer localtime.txt to your Linux account.
    1. First click on  localtime.txt and copy the text.  (If you are using Internet Explorer or any other reasonable browser, you can quickly copy the text by typing Control-A Control-C.)

    2. In your Linux telnet session, type “pico newfile.txt”.  Then paste the text.  (In most telnet clients this can be accomplished by right-clicking and then choosing “Paste.”)  After pasting, type Control-O to write the file, and then type Control-X to quit.

X Windows

Why would you want to use X Windows? Well, you don't. Trust me. It just brings more headaches and frustration, for you and for me. So please don't use it. OK, you can stop reading now. I've warned you.

OK, if you're still reading (even though I told you not to) then I'll tell you a secret: You might want to use X Windows because it will allow you to do everything from Linux, without having to use your Mac or PC to edit or transfer files.  For example, in X-Windows you can use the Mozilla browser to download the sample Perl scripts directory to your Linux home directory, and you can also use cool Linux editors like gedit, and disregard lame editors like pico.

For Windows users, you can download a good X Windows system here. After installing it, find the “Xmanager 1.3.9” icon on your desktop, or in your Start menu.  Then click on the Xconfig icon. When Xconfig opens, click on the XDM tab, then choose XDM Query.  Next to it type in “10.0.1.200” for the host.  Next, click on the Window tab.  Choose Single Window Mode and click OK.  Now you can run the X server by clicking the Xmanager icon.

For Mac users, you can try XTen here.  It says it expires after 14 days though.  For OS X users, you can try Fink here.  I'm not sure if these X servers support XDM though. If not, then you won't be able to connect to our Linux server.