Web and Database Development Environment Perl Example

Please go through the HTML Example before doing this example.

Create a sample perl file

  1. Go to the examples sub-directory of your web development directory:

    [username@l-lnx101 username]$ cd /webdev/user/username/examples

  2. There is a single perl script which reads in data from temp.txt and creates a sqlite database. You can edit/view the files with nano by typing nano <filename>.
  3. Using nano, we can create tutorial.pl:

    [username@l-lnx101 examples]$ nano tutorial.pl

  4. Copy and paste the following code into your nano screen:

    #!/usr/bin/perl -w

    use strict;
    use Socket;
    my $remote_addr = $ENV{'REMOTE_ADDR'};
    my $iaddr = inet_aton($remote_addr);
    my $remote_host = gethostbyaddr($iaddr,AF_INET);

    print "Content-type: text/html\n\n";
    print "<html>\n";
    print "<head>\n";
    print "<title>Remote IP</title>\n";
    print "</head>\n";
    print "<body>\n";
    print "<p>\n";
    print "REMOTE_ADDR is $remote_addr.<br>\n";
    print "Lookup of $remote_addr is <b>$remote_host</b>.\n";
    print "</p>\n";
    print "</body>\n";
    print "</html>\n";

  5. Save the file and go to http://webdev.cs.uiowa.edu/~username/examples/tutorial.pl where username is replaced with your divmsid.
  6. The page when viewed on l-lnx100 in the lab looks like:

    Lookup of is l-lnx100.divms.uiowa.edu