deels has asked for the wisdom of the Perl Monks concerning the following question:

Hello.This is my first time here in perlmonks.org. I'm studying at uni at the moment, and I have to do a website using Perl with CGI application. the problem is,I don't know where to start!!*panicked* Can somebody please,at least help me by giving me the beginner's script in CGI? the website needs to have a form that's gonna be filled by customers buying stuff online. I appreciate every little help!!thanks in advance!!:)

Replies are listed 'Best First'.
Re: how do I use Perl with CGI?
by dmmiller2k (Chaplain) on Jan 18, 2002 at 08:05 UTC

    You're gonna hear this alot, but let me be the first to tell you to RTFM.

    There are many resources, both in print and on the web, but one place to start might be right here on Perl Monks, with Where can I learn about CGI or Web programming in Perl? and Setting up Perl/CGI with Windows.

    As for print references, there are many; some good, some bad; in particular, what worked for me (or another) may not necessarily be appropriate to your current level of programming expertise in general and/or perl expertise in particular.

    In my opinion, learning programming (in general) and Perl (in particular) is like solving a jigsaw puzzle.

    You may have several pieces connected, but with no frame of reference for where they fit into the big picture (i.e., you've written a simple program or made a minor change to a working one, but couldn't take it further without help). You may have assembled the edges first, in order to define the field (i.e., learned the basics). You may have a large section completed minus one or two missing peices (i.e., perhaps you understand arrays and hashes, but get lost in multilevel structures with many references).

    Which book(s) you'll find useful all depends upon how complete your jigsaw puzzle is and which pieces you are looking for.

    To recommend one or another is rife with controversy, and is therefore venturing into a minefield in a forum such as this, risking offending one person or another or starting a debate, so I'll leave that to others.

    dmm

    If you GIVE a man a fish you feed him for a day
    But,
    TEACH him to fish and you feed him for a lifetime
Re: how do I use Perl with CGI?
by impossiblerobot (Deacon) on Jan 18, 2002 at 07:54 UTC
    There are a number of good Perl/CGI tutorials on the web.

    Update: For starters, look at Ovid's Web Programming Using Perl. Not only does he explain what to do and how to do it, but he also explains what not to do (and how not to do it)!

    (I should also have mentioned that there are even MORE bad tutorials out there.) :-)

    This will probably get you going pretty quickly.

    Impossible Robot
Re: how do I use Perl with CGI?
by Chmrr (Vicar) on Jan 18, 2002 at 08:06 UTC

    In addition to the site mentioned already, I would specifically single out Ovid's CGI Course (Update: Oops! I was beaten to it!). In addition, I would suggest http://learn.perl.org and / or the most useful Learning Perl book.

    perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'

Re: how do I use Perl with CGI?
by mattr (Curate) on Jan 18, 2002 at 13:02 UTC
    I agree with the above but would like to add a caveat - if you are up against a tight deadline this could be a dangerous project to take on by yourself. You might want to work on it in consultation with someone else who is experienced.

    The reasons are security and commercial liability. Imagine if you were in your client's place, and the guy you hired was in your shoes! What if this shop starts spending money advertising? There are guidelines well discussed at Perlmonks and elsewhere about what is good to do and not to do, but if your system fails it might 1) incur lost sales for every hour it is down, or 2) enable a breach in security such as publishing passwords or allowing crackers to access other parts of the server.

    If it is not such a critical project, then jump in both feet first! But I would recommend doing it with a lot of reading. In particular many free programs available on "scripting" sites out there have well known security holes documented here and elsewhere. Probably better I'd think to keep things very simple and roll your own.

    I think the main parts of your program will have to be getting the form data, neutralizing dangerous data that might be in it (such as checking length and removing pipe marks, line feeds, and control characters), and appending the data to a text file while maintaining/checking a lock on it in case of frequent access. There are also messages you will want to supply to the visitor such as confirmation of the data and lacking information in required fields. The rest of the processing can be done manually, for example by downloading a tab-separated file into a spreadsheet program.

    But if you have experience programming in other fields I would guess that 2 months, including learning Perl from scratch and doing a lot of studying of the issues, is probably enough time to get up to speed and be confident of what you are doing while keeping your client happy and involved. As time goes on you will be pleasantly surprised by how much you are able to do, but that power is directly related to how solid your foundation of understanding is. Good luck!

Re: how do I use Perl with CGI?
by Desdinova (Friar) on Jan 18, 2002 at 09:05 UTC
    Persoanlly I found CGI Programming with Perl to be helpful. Of course I will second all the metions of Ovid's course, it is really good esp in regard to writing secure scripts.. its one thing to know that you should use taint mode its another to know why.