College of Liberal Arts & Sciences
Web and Database Development Environment Perl Example
Please go through the HTML Example before doing this example.
Create a sample perl file
- Go to the examples sub-directory of your web development directory:
[username@l-lnx101 username]$ cd /webdev/user/username/examples
- 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>.
- Using nano, we can create tutorial.pl:
[username@l-lnx101 examples]$ nano tutorial.pl
- 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";
exit; - Save the file and go to http://webdev.cs.uiowa.edu/~username/examples/tutorial.pl where username is replaced with your divmsid.
- The page when viewed on l-lnx100 in the lab looks like:
REMOTE_ADDR is 128.255.44.124
Lookup of 128.255.44.124 is l-lnx100.divms.uiowa.edu