2

I was trying to learn Perl then I ended up writing a script that tries to find all possible schedules given course names, where a possible schedule means that there are no clashes between the course times by iterating through all sections.

I crawled my university schedule of classes and placed them in a messy data structure hash to a hash to a 2D array where first hash indicated the Subject and second hash indicated the Course number then an array of sections where each section is an array of all the data. (not the most appealing data structure)

I then, processed all schedules combinations by iterating through all possible schedule combinations and return all schedules that didnt have a clash as a 3D array (where each entry was a schedule and each schedule had courses and each course had its specific data)

Now, I can hard-code the input in the script as a 2D array where each element consisted of Subject name and course number.

What I want to do now is to transform this into a website.

I took an online course on database but I don't have a clue on how to handle databases from Perl or whether this is a good approach.

I don't know how to store the data crawled permanently so it could be used for further computations.

I know basic HTML and CSS and Javascript but I have no idea on how to integrate the script with them and take the input from the user (I only know how to do that in Javascript). Google lead me towards "cgi-scripts" but I don't anything about servers except that they are responsible for computation done by website and one of them is called Apache or AJAX. I am not sure whether this is true or not but I want to give you an idea of my level of expertise.

Could you please point me in the right direction by telling me what do I need to learn in order to be able to make this website.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Ibrahim Assal
  • 33
  • 1
  • 7

3 Answers3

4

I took an online course on database but I don't have a clue on how to handle databases from Perl or whether this is a good approach.

Database access in Perl is done via DBI. You can use DBIx::Class to get a nice OO abstraction for it.

I don't know how to store the data crawled permanently so it could be used for further computations.

Databases are a good choice.

I know basic HTML and CSS and Javascript but I have no idea on how to integrate the script with them and take the input from the user (I only know how to do that in Javascript).

Use a <form>. Set the action to the URL of a server side program. Submit the form.

Google lead me towards "cgi-scripts" but I don't anything about servers except that they are responsible for computation done by website and one of them is called Apache or AJAX. I am not sure whether this is true or not but I want to give you an idea of my level of expertise.

An HTTP server listens for HTTP requests and provides HTTP responses. Browsers (and search engines, and other clients) make HTTP requests to servers that host websites. The servers respond with the data (HTML, CSS, JavaScript, Images, etc) needed to render the site and the client renders it (or indexes it, or whatever).

Apache HTTPD is one of the most commonly used HTTP servers.

CGI is means by which an HTTP server can determine what to respond with by running a program instead of just handing over a static file. It is very simple but not very efficient. Some alternatives are described in this answer.

Ajax has nothing to do with this. It means "Using JavaScript, in a web page, to tell the browser to make a new HTTP request (without leaving the page) and make the response available to the JavaScript".

Community
  • 1
  • 1
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
3

This is going to be a partial/vague answer..

For database, what you want to do is to learn to use DBI this is a database implementation independant api to talk to data bases (it can even write to csv files!). You would also need a driver for your database of choice.

As for website it is beyond my skills, there are many ways to do it. Perl would be used server side via something called CGI. Javascript on the other hand is typically processed on the client side, and is used to add dynamic elements to your site. Apache is a web server software, it takes care of talking with your browser and passing it relevant html pages, you might need to use it, but you would not need to code anything for it for basic use-cases.

For perl webpages, you can start with this tutorial to understand better, and then look to perl monks for a better(and more up-to-date) answer. This post will also give you more practical advice like to use Dancer

Karthik T
  • 31,456
  • 5
  • 68
  • 87
  • 1
    In addition, I'd recommend `Dancer` as a micro-framework for building simple web sites and services. It simplifies a lot of the request/response handling, and during development it can be tested locally on a built-in web server. – Neil Slater Jul 23 '13 at 09:09
  • @NeilSlater yup, after my own blunderings, I noticed that dancer is the first think perl monks points to.. maybe ill emphasize it more. – Karthik T Jul 23 '13 at 11:43
3

For a pure perl setup, the HTTP::Daemon and HTTP::Response modules are your best friends. I tried to write a web server using nothing but IO::Socket and nearly drove myself crazy.

Getting started is pretty easy.

use strict;
use warnings;
use HTTP::Daemon;

my %opt = (
    'listen-host' => 'localhost',
    'listen-port' => 8808,
);

my $d = HTTP::Daemon->new(
  LocalPort => $opt{'listen-port'},
  LocalAddr => $opt{'listen-host'},
  Reuse => 1,
) or die "HTTP listener failed at $opt{'listen-host'}:$opt{'listen-port'} - $!";

print "Started HTTP listener!\n";
my $c = $d->accept;

Now your script will sit there until you get a connection from a browser. Of course you still need to send a response, so see HTTP::Response on how to send data back.

Mintx
  • 151
  • 4