Quick Search for:  in language:    
Ever,wanted,build,your,applications,absolutel
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
Perl Stats

 Code: 74,273. lines
 Jobs: 24. postings

 How to support the site

 
Sponsored by:

 
You are in:
 

Does your code think in ink?
Login





Latest Code Ticker for Perl.
Click here to see a screenshot of this code!CGIScripter
By David Simpson on 11/24

(Screen Shot)

Calender
By Jeff Mills on 11/20


quikpoll
By Jeff Mills on 11/20


Encrypt Password
By Jeff Mills on 11/20


Rock, Paper, Scissors w/ GUI
By Kurt Rudolph on 11/19


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!

Affiliate Sites



 
 
   

A fast 4 hour introduction to perl

Print
Email
 

Submitted on: 7/10/2002 4:11:33 AM
By: Ashley Harris 
Level: Beginner
User Rating: By 17 Users
Compatibility:5.0 (all versions), 4.0 (all versions)

Users have accessed this article 12893 times.
 

(About the author)
 
     Ever wanted to build your own web applications? But you have absolutely no idea where to begin? This tutorial will get a beginner started in perl in under 4 hours, starting with the installation of perl.

 
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
1) You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.

This is a 4 hour course that will teach you the basics of Perl CGI programming. It goes right through from installation of the programming language to simple programs and places to go from here.

FIRST HOUR:

Set the clock, people! I'll discuss a simple 'hello world' program and introduce some very important background info. Namely variables, looping, how to stop the Dos prompt from disappearing immediately, and how to make the output as a webpage.

At the end of the 4th hour, you should be able to make your own web applications, and within a few weeks from there, you should be able to get Perl to do everything from graphics design to virtual reality to web browsing to counters to guestbooks to login scripts to banner rotators to online auctions. There are some aspects (cookies, for instance) that are not covered here, but I have included links to packages to do it for you.

One thing about this language, it is incredibly well supported. There are newsgroups, books, libraries, and even an online university (apparently). Any of these will be more then happy to help you if you are having problems.

Good luck!

WHY MAKE YOUR OWN WEB APPLICATIONS?

First, while there are companies out there can develop your web applications (CGI scripts) for you, they all have one or more downsides:

  • They can't do all of what you want to do.
  • You have no control.
  • They cost money.
  • They stick banners ads on your pages.
  • It relies on their server.

You’re about to learn how to make your own web applications, ie. make one of these programs yourself. While at first it looks daunting, don't worry, I must off learnt it, right? (I'm a 16 year old, I learnt it in about 2 weeks without this kind of tutorial, you’ll be fine).

The first step, you need to find a copy of Perl. Go to perl.com and find one for your operating system. It's available for Linux, Mac, Win32, and Dos. All of these are free for download.

You need to install it, on a Mac, it's easy, just use Stuffit expander to open it and it'll be fully installed. On a windows or dos machine, installation usually goes fine, but sometimes the extensions get messed up. On Linux, you've already got it (/usr/bin/Perl is where it usually is).

Now, if you use a Mac, double click on Mac Perl, if you use something else, open your favourite text editor (NOT MSWord, ClarisWorks, try Notepad instead).

If you have windows, it may be worth getting the open-Perl-IDE. Basically it gives you an ‘everything’ Perl package, ie text editor, debuger, etc. The url is: http://open-Perl-ide.sourceforge.com/. I recommend it.

Now that we’ve installed it all, let's try something simple, How about a 'hello world'?

Type this in:

#! /usr/bin/perl

# display some text, then wait for a return, then end.

print "Hello World\n";

<STDIN>;

If your using a mac, press command-shift-r, openperlIDE, press F9. If your using something else, save it as 'hello.pl' and (if you have a command prompt) go to the perl folder, and type 'perl "hello.pl"'. If your using Windows, just open it in Perl. (right click, and go ‘open with’)

Now, let me explain the script.

'#!' is a command to the Operating System, It is like saying 'this document needs to be compiled by'. The path name that follows is the path to your version of perl, if you don't know it, '/usr/bin/perl' is a good choice. This line must be the first line of your script.

'#' is how you place comments in your scripts. (Notice that '#!' line is really a comment.) Everything from the '#' to the end of the line is a comment.

'print "Hello World\n";' Well, 'print' makes sense, '"Hello World' makes sense, what's the '\n'? '\n' Means start a new line, you must put this in double quotes else it says something like 'SCALAR{346F8C2}', which isn't what you want.

'<STDIN>'? That means, wait for something, followed by a return. This is to stop the Dos Prompt from quickly disappearing for windows users.

You may be wondering, why does he keep putting a ';' at the end of every line? Simple, ';' means 'end of command' You must use these to separate one command from another.

MAKING A WEB PAGE. (CGI scripts)

You may be thinking: How does "Hello world" make a web page, the answer, it doesn't. You actually need to tell it the html code. Type out the following script: (Take care to get the '/' and '\' right).

#! /usr/bin/perl

print "Content-Type: text/html\n\n";

print "<HTML><HEAD>\n";

print "<TITLE>Hello World</TITLE>\n";

print "</HEAD><BODY>\n";

print "<B>HELLO WORLD</B>\n";

print "</BODY></HTML>";

To be any good at this, you need to know HTML. I'd suggest borrow a book from your library on it. It is something you need to know.

If you already know HTML, this script should make some sense. Except for maybe the "Content-Type: text/html" line. This tells the browser what's coming at it, If you wanted just plain text, it'd be 'text/plain'. If you wanted a image, It'd be 'image/gif' or 'image/jpeg', if it was a download, it'd be 'application/x-stuffit' or 'application/x-zip'. This line is only needed when your using CGI scripts, if your placing a html document on a server, the server will look at the extension of the document, and decide the line from there. If you place it in your HTML documents, it will be prepended to your webpage and either show up the top of the browser, or cause the entire document to not show. Something which you don’t want to happen.

VARIABLES

This is the one and only reason for CGI scripts, making the scripts variable.

Type out the following script:

#! /usr/bin/perl

$x = 4;

$y = "ello world";

print "$x is the number\n";

print "H$y is called a scalar";

<STDIN>;

This has the result of:

4 is a number

Hello World is called a scalar

Now, try the following:

#! /usr/bin/perl

$x = 5;

$y = 9;

$cost = $x+$y;

print "That comes to a total of $$cost";

This gives the result of 'That comes to a total of ', which isn't what you want. So, to fix it, I'll introduce you to the idea of 'escaping', replace the last line with:

print "That comes to a total of \$$cost";

This gives the desired results. the '\' tells perl to treat the next character as it looks. This also works for:

print "He said \"Hello!\" and handed me the flowers";

You will shortly find that the @ sign needs to be 'escaped', so an email address should look like "mailto:ashley\@ashleyharis.com".

LOOPING

Type in the following program:

#! /usr/bin/perl

for $x (1..50)

{

print "The value of \$x is $x\n";

};

this gives the result:

The value of $x is 1

The value of $x is 2

The value of $x is 3

The value of $x is 4

...

The value of $x is 50

 

Notice that the semi colon doesn't go after the ‘for’ command, only after the closing bracket '}';

If you omit $x, the variable $_ is used instead.

x..y is a rather 'exotic' operator, Perl is the only language that supports it. C style for loops are also supported.

You could also use the while operator:

#! /usr/bin/perl

$x = 0;

while ($x =< 50)

{

print "The value of \$x is $x\n";

$x++;

}

('=<' means less then or equal to).

(Notice that the '$x = 0' line is optional, but, perl will warn you if you do this).

Or, you could use the until operator:

#! /usr/bin/perl

$x = 0;

until ($x > 50)

{

print "The value of \$x is $x\n";

$x++;

}

('>' means greater then).

Or, you could use it this way:

#! /usr/bin/perl

print "The value of \$x is ".($x++)."\n" until $x > 50;

As you can see, in perl there are many ways of doing things.

Try these scripts, and try to fiddle round with them, change the occasional number, change the variable names. See what happens, etc. It's the only way to learn.

 

SECOND HOUR:

Welcome back! Your learning Perl! Just 3 hours to go before you can create your own dynamic websites!

FILE HANDLING

File handling is a rather complex concept, but, it is basically another file on the server that you can read and write to.

#! /usr/bin/perl

open(MYFILE,"C:\\autoexec.bat");

while(<MYFILE>)

{

print;

}

close(MYFILE);

NOTE the ‘\\’. This is for Windows users only. (‘\’ is special, remember…)

This simply reads in a document and prints it all, when it's done, it closes it for someone else to use.

You may remember that <STDIN> waits until the user presses enter? Well, I lied, It really gets data from the keyboard (STanDard IN) and returns it to the variable $_. Ending when it reaches a new line. So <MYFILE> gets data from MYFILE (which is "htmlheader.txt"). Ending at the end of a line. It then does this over and over until, basically, it’s out of file.

How does the while loop finish? Simple, most the commands in perl either return 1 (true) if they were able to do their job or 0 (false) if they didn't. The minute it reaches the end of the file, it can't go any further, so it returns false, and ends the loop.

By default, print prints the variable $_. As a matter of fact, many operations use this variable by default.

#! /usr/bin/perl

open (FILE,">myfile.txt");

print FILE "This is a test of something to be in this file";

close FILE;

Notice the ">" in the file name? That tells perl the write to the file, not read from it. The file is created if necessary, and always emptied before hand.

Notice how I used the print command? I told it where to print. If I had left out the word FILE, it would have printed to the screen or a web browser. If I had used STDERR, it would have written to the screen or (If used on a server) the servers error logs (/var/log/http/error_log).

If you want to add something to the bottom of a file, have a look at the following example:

#! /usr/bin/perl

open (AFILE, ">>myfile.txt");

print AFILE "This line appears at the bottom of the text file\n";

close AFILE;

notice the ">>" in the filename, this tells perl to write to the end of the file, not the start of it.

 

FORM PROCESSING

First things first, you need to get a copy of 'cgi-lib.pl'. It is a free download. You should be able to find it at www.perl.com/CPAN/. Or just type in 'cgi-lib.pl' in altavista.

There are a lot of new things introduced in this script, be patient, I'll explain them.

#! /usr/bin/perl

require 'cgi-lib.pl';

if (ReadParse(*in))

{

$name = $in{name};

$email = $in{email};

print "Content-type: text/html\n\n";

print "<HTML><HEAD><TITLE>THANKYOU</TITLE></HEAD></BODY>";

print "Your name is $name and your email address is $email";

print "</BODY></HTML>";

}

else

{

print "Content-Type: text/html\n\n";

print "<HTML><HEAD><TITLE>PLEASE ENTER YOUR NAME AND EMAIL TO CONTINUE</TITLE></HEAD><BODY>\n";

print "<FORM method=get><Input type=text name=email> Email address<BR>\n";

print "<INPUT type=text name=name> NAME<BR>\n";

print "<INPUT type=submit></FORM></BODY></HTML>";

}

OK, first thing, the 'require' statement tells perl to load the library 'cgi-lib.pl'. This is where most of the new stuff is stored.

'if'? Ah, whoops, forgot to explain them, they work simular to the 'while' statement, but, the only do what's in their brackets once if it's true, never if it's false. They can also have a 'else' bracket to do if it's false, but only if it’s false. I know that didn't make much sense, so, here are some examples:

#! /usr/bin/perl

$age = 6;

if ($age > 18)

{

print "Have a beer and ";

}

print "Have a coke";

If age is greater then 18, it displays 'Have a beer and Have a coke', if you are under age, it says "Have a coke". Make sense?

#! /usr/bin/perl

$age = 15;

if ($age > 17)

{

print "Get drunk";

}

else

{

print "Make friends";

}

print ", and be happy";

If your older then 17, it says "Get drunk, and be happy" otherwise, it says "Make friends, and be happy".

Now, back to me explaining that first script.

ReadParse(*in)? This is the magic keyword. It gets everything that was sent to the script, and places it in a special variable called $in. What's so special is it's a hash. More on these later. The capitalisation of ReadPase is important.

$name = $in{name};? I told you $in was special. Whatever is between the {} is the name of a field on a web page. ie (<Input type=text name=whatever>)

This is hard this bit, so, look at my examples over the following issues, and, in your programs, just copy and paste it then modify it until you get the idea of it.

 

EMAILING FROM A CGI SCRIPT

This is a hard topic, so, like the last one, you may need to resort to copy/paste/modify.

#! /usr/bin/perl

open(MAIL,"| /usr/lib/sendmail -t -oi");

print MAIL "To:ashley\@ashleyharris.com\n";

print MAIL "From:happyuser@myhouse.com\n";

print MAIL "Subject:It worked\n\n";

print MAIL "This is just a quick message to say everything worked.";

close MAIL;

OK, the '|' means don't open a file, open an application, and because It's before the filename, write to it. The -t and -oi tells sendmail that we'll enter the headers ourselves (better security), and to send when we close. This will only work from the server, and, some servers will remove it to prevent spam.

HOW TO ACTUALLY RUN THE WEB EXAMPLES OVER THE INTERNET.

This is a common question I get. You need to upload it to your website using and FTP program, then find the option to change the access privileges. You need to make it readable to everybody, executable by everybody, and the creator can write to it. If it asks you for a number, type 755. If you can telnet in, go to the folder, and type 'chmod 755 THEFILENAME'.

If you are using libraries (ie 'cgi-lib.pl', you need to do the same to them aswell).

Didn't work? Try putting it in a folder called 'cgi-bin' in your website folder. If that doesn't work, try backing up a folder (go to dir. ".."), and either go into or create a folder called 'cgi-bin'. If that doesn't work, try talking to your system administer or web hosting company. If you’re using something like geocities, don't even bother, you need to find one that will allow you to run scripts on their servers. (There aren't many free ones).

If your on a budget, try going to demented.org. They offer free 20MB web hosting with CGI script support, perl, everything. No ads. Sign up, and upload your scripts, do the previous paragraph, and try to access the page with a web browser. You should see what you want.

Now, these things go wrong sometimes. So, if you see an error:

500 First, check to see whether you made the script and every other script and library on the site executable. Then, run the script through your own version of perl, see if it works. Then, check the top line of the script to see if it's '/usr/bin/perl'. Then, check the server error logs, they should offer you some assistance. Basically, it means an error has occurred, and you need to fix it. (5 means permanent failure)

404 Any web user knows what this means, make sure you get your capitalisation right. Also, check to make sure you have the right privileges, and that every folder it's in is readable by everybody. (In Linux, if you can't read it, it's not even shown). Also, try placing /cgi-bin/ between your Domain and script name. ie. http://192.168.0.1/cgi-bin/htmltest.cgi instead of http://192.168.0.1/htmltest.cgi.

403 When you set up your script, and made it executable, you forgot to make it readable. Or something along those lines. Try making it readable/writable/executable to everyone (mode: 777)

THE THIRD HOUR!

You think you know this CGI stuff cold! You can your ‘hello world’ page look the coolest. Well, now the bombshell drops:

In this hour, I'll demonstrate Functions and Subroutines. How to make libraries, and placing headers and footers on every page.

FUNCTIONS+SUBROTINES

Functions or subroutines (They are the same thing in Perl). Are common bits of code. It is pretty hard to put into words, so, here are some examples.

#! /usr/bin/perl

for $x (1..5)

{

for $y (1..5)

{

print add($x,$y);

print "\n";

}

}

sub add

{

$num1 = shift;

$num2 = shift;

return $num1+$num2;

}

 

 

 

#! /usr/bin/perl

print "The factors of 65 are".factors(65)."\n";

print "The factors of 72 are".factors(72)."\n";

print "The factors of 360 are".factors(360)."\n";

sub factors

{

$num = shift;

$temp = "";

for $x (1..$num)

{

# Is it a whole number when you divide $num by $x?

if (int($num/$x) == $num/$x)

{

# Append it to $temp

$temp = $temp." $x";

}

}

return $temp;

}

shift gives you (returns) the next subroutine argument. (Thing in the () ) when the subroutine is called.

int gets a number, and removes everything after the '.'. No, it doesn't round the number.

Notice the '==', DO NOT, I repeat, DO NOT use '=', terrible things can happen.

LIBRARIES

Libraries are a group of functions in a single file. Here you would included functions to: pick a banner, check a password, read an account, draw a header, etc. Anything that you are likely to use on more then one page.

Libraries should be their own file. They don't need to have the '#! /usr/bin/perl' line at the top, but, it's good to.

Libraries are exactly the same as perl scripts, except, no code should execute when they're run.

When on a server, they need to be set to executable. See Pt. 2, getting your scripts to actually work on the web.

One more thing, at the end of each library, you need to included the following line:

1;

Why? This is a just a test used to see if there is something there.

To use a library in a script, simply place 'require "LIBRARYNAME.PL"' at the top of each script that you want the library to be used.

PLACING HEADERS AND FOOTERS ON EACH PAGE.

This is related to the previous 2 topics, In your script, it would have:

#! /usr/bin/perl

startbit();

print "This is a web page";

print "<P> I"m doing something";

endbit();

and in your library, you'd have:

sub startbit

{

print "Content-Type: text/html\n\n";

print "<HTML><HEAD><TITLE>This is my webpage</TITLE></HEAD><BODY leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>";

print "<IMG border=0 src=\"http://www.clipart.com/titlebar.gif\"><IMG border=0 src=\"/singlebluepixel.gif\" width=100% height=50><P>\n\n\n";

}

sub stopbit

{

print "<SMALL><CENTER>Copywrite 2001, Ashley Harris</CENTER></SMALL><P></BODY></HTML>";

}

1;

This can significantly reduce file sizes and upgrade hassles. As a matter of fact, this one bit of functionality was the reason I learnt CGI.

Mess around with this, see what you can do with it.

THE LAST HOUR!

In this issue, I'll show you how to use JavaScript to place the result of a CGI script in an ordinary webpage. I'll also give you a list of suggestions on where to go from here.

USING CGI IN ORDINARY HTML FILE

Let's say your website is already well established in it's current location. You don't want to move it, on the other hand, you want to place some functionality in your webpage, lets say, a hit counter. And you don't want to put the entire webpage inside a CGI script, escape every little quote and Newline, maybe your site wont fit on demented.org?

If your a little bit web weary, you'll have heard of a language called JavaScript. If you really web weary, you'll know that they can be set out like this:

..

<SCRIPT src="myscript.js"></SCRIPT>

..

And the JavaScript code included in the file myscript.js is loaded, execute, and anything written to the screen, is placed at that point. This is perfect for CGI, because, perl can make the .js file. The bad problem is, you need to learn practically a new language, and because your writing a program to write a program to execute on every possible computer, which will cause most people eyes to gloss over about now. First, here is the code for the CGI script. (This example is a counter).

#! /usr/bin/perl

open (COUNT,"counter.txt");

$count = <COUNT>;

close COUNT;

$count++;

open (COUNT,>counter.txt");

print COUNT $count;

close COUNT;

print "Content-type: text/html\n\n"; #Yes, I'm sure that's right.

# Start the JavaScript document.

print "document.write(\"";

print "There have been a total of $count hits on this site since I built it";

print "\");

# Ended

On your webpage, you'd include the code:

<SCRIPT src="counter.cgi"></SCRIPT>

Done! Don’t believe me! Try it out!

WHERE TO GO FROM HERE

One things for certain, I haven't taught you everything about perl, why? Because, nobody knows it all. So, what can you do now?

  • Finish learning the basic structure. I didn't teach you anything about hashes or arrays or complex data structures. I didn't even tell you how to change directories or pass commands to the system. Most of these can be found in the first few chapters of a book at your local book store. Also, if you have the mac version, your lucky, you have an entire manual under the help menu.
  • Regular Expressions. These are very hard to learn, and very hard to read. I understand them, but don't believe I could teach them to you. There basically find and replace commands on steroids. They can do things like put the commas in long numbers, extract the text between two words, extract the text between two words of x length. Reformat paragraphs, anything that involves text and doing stuff to it.
  • Object orientated programming. When you being to extend yourself, especially towards the graphic end of perl, you should under stand this concept. Once again, I know it, but not well enough to teach you.
  • User Interface. Go to www.perl.com/CPAN/ and download the library (module) 'tk'. (If you don't have it already), This allows you to a GUI onto the your perl scripts. I have visual basic 6, so, realisticly, I can’t be screwed doing this, but, especially on linux, it'd be worth doing.
  • System interaction. Do you know there is 1400 digit calculator on linux (type in bc at the command prompt). You can interact with that in a simular way that I showed you with email.
  • Graphic design. Ironic, isn't it? A command line program is probably the best graphic design package ever. It can make some pretty impressive graphics, and turn crumby graphics into super ones. Go to CPAN (see above) and download the 'GD' package. You can also make them on the fly using the 'content-type: image/gif' line. If you have a poor imagination, skip this step.
  • VRML. Virtual reality. You can make some AMAZING scenes using this. If you don't have an amazing imagination, skip this step. I messed around with meshes for a while, but, I have blender, so, I haven’t pursued Perl VR.
  • Interaction. perl can talk to FTP servers, mail servers, telnet servers, other webpages, it could even talk to Napster (when it was up).
  • The huge network behind perl, Cpan. Go here, learn much.
  • Well, it's been fun, and I hoped you've learnt a lot. So, to test your skills, I've set up some basic projects for you to attempt. If you remember from the first issue, there are a billion ways to do each of them, but, I've told you all of the things you'll need. Good Luck!

TASKS:

1) I want to enter my email address in a text field, and, it will be added to the end of a file.

2) I want to have a user enter their email address, but, have perl go through a file to see if it's already there. if not, add them.

3) I want to be get a large text file, and turn all the A's into Z's. (This is a pretty basic regular expression)

4) I want to remove all HTML tags that a user enters in the email field of a form. (A regular Expression that swaps '<' with '<').

5) A regular expression that reverses the order of every word in a document. (Ignore punctuation)

6) A regular expression that can abbreviate all words in a document to 4 letters.

7) A script that compares two passwords typed, sees if they are the same, and longer then 5 letters.

8) A button with text, and a coloured bar on the left. (Graphics Design)

9) A script simular to the last, that you pass the text to in a form, and it makes a button with it.

You half way there!

10) A VRML scene, resembling rolling hills. With a black sky. Skip this one if you want.

11) Take a snapshot (CMD-SHIFT-3 or Print Screen) of the previous task, crop it to just the graphic, and have a perl script read it in (using GD), and place stars in the sky.

12) A guestbook, that displays the number of entries, and stores comments, email, and the name.

13) A script that will tell you how long it has been (Years, Hours, Minutes, Seconds) since Midnight, January the 1st, 1970.

14) A script that will tell your BMI (Body Mass Index) (How Fat/Thin you are). The formula is: You divide your weight in KG by your height in M's, and then square it. < 10 = dead, 10-20 Underweight, 20-25 Normal, 25-30 overweight, 30+ Obese. Go to Commission Junction, (www.cj.com), and find a good diet program. If they are overweight, show them the link to the diet program.

15) Go to the love calculator (www.lovecalculator.com), and fiddle around with the names of your high school teachers and your pets for a while, now, try to build something simular. Include a clause, so that if you AND your sweetheart names are placed in there, it automatically gives you 100%.

16) Get the LWP module (Load Web Page, or Lib-www-perl, depending on who you talk to). Make a script that will constantly request an address. Now, Make it POST data to that page, every time it reloads it. What it rereshes is up to you. (I'd suggest something that pays per hit, or a 'vote-for-me' button, but, it's up to you).

17) Sign up for a free POP3 email account at anywhere, dig out script #2, and make it check the email address (yours at whatever.com) frequently, and, if there is any email, to forward it to everyone in the list. Make sure to strip all the headers except subject. Remember to delete the email after sending it.

18) THE ULTIMATE. Same as above, but, instead of using POP, use a hotmail account. You'll need to use the LWP module and heaps of regular expressions for this.

If you've reached here, and have done all the tasks above. You are now truly a web programmer. Give yourself a pat on the back, and email me (ashley___harris@hotmail.com) giving any comments or suggestions.

if you've complete about 10-15, Be proud, you can now have a complete change of careers if you wish..

If you've completed about 5-10, That's still an achievement, can any of your friends do that? Keep trying.

 

One more challenge? OK

19) Make a script that will take one field with both a song title and an artist in it (or one or the other). Make the script search a peer to peer network (fastract, gnutella, etc) for each and every combination of all the words entered, and in either the artist or title field, each time for 100 songs on an ADSL or better, with a bit rate of 64 or more. Remove duplicates, and ask the user for which one they want (sorted by relevance). If they choose to download one, download it locally, then upload it to an FTP server, then email a copy to the person who downloaded it. And then remove from your server. If anyone else does a search, make sure it searches the FTP server first, and gives priority in the search listing for any on the FTP server. Also, if your using a free web site as your FTP server, use the LWP library to automatically sign up for more space when the current account is filled with songs. Include a script that will search commission junction (cj.com) for any new merchants with 'music', 'mp3', 'sound', etc as a keyword, and add their 468x60 banner to a banner rotator at the top of each page. Also have a link to a paypal (www.paypal.com) account so that anybody who wishes to buy advertising can do it easily. Remember to included statistics such as how many people clicked on their banner, what were their IP addresses? etc. Market it, and, pay me at least 1% of your net profit.

I'm not expecting you to actually do that one, but at least try it.

I hope you learnt something from this tutorial, hopefully, by now your good enough at perl to learn the rest yourself.

Please tell me what you think of this tutorial.

Ashley Harris


Other 1 submission(s) by this author

 

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this article(in the Beginner category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
7/10/2002 8:41:40 AM:Ashley Harris
Come on guys, 29 of you have read this, and nobody has left any feedback, or voted, or anything. If it was cr@p I need to know, right? Ashley.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
7/10/2002 3:53:37 PM:Peter Geer
I'd say this was a fairly good "getting started" type article. I liked that you provided some practical examples of what you can do with CGI. I found it useful and informative. Aside from some minor quibbles, my main criticism is that I think you tried to pack too much into too little space. Perhaps it would have been better if you'd written two articles, say an introduction to Perl and a second article on CGI that built on the first. Or maybe if you'd just assumed the reader had some programming knowledge rather than trying to start from nothing. Either way, I would have liked a little more focus on web development. On the whole, though, I think you did a pretty good job.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
7/11/2002 6:07:16 PM:GreyMatter
Very Good!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
7/11/2002 9:41:46 PM:*JJ*
LOL!!!! Just a note on the title... Think again how this doesn't make sense... "a FAST 4hour introduction?" lol. :)
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
7/12/2002 11:22:54 PM:totomds
good job =)
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
7/13/2002 7:54:17 AM:Rusty
Thanx for the great crash course. My only suggestion would be update your suggested downloads.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
7/15/2002 2:56:48 AM:zeff calilung
Im so interested to learn Perl could you send me more topics? pls. What is: the Diff Bettween Perl, CGI, PHP,ASP? which do you prefer to use? which is easier to write and understand?
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
7/18/2002 12:36:28 AM:janilane
the effort alone to teach was amazing ! more tutorials please !!!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
7/23/2002 4:02:25 PM:Rafal Krolik
4 hours AGO, I did not know PERL....things have changed. Good Job!!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/3/2002 2:34:27 AM:happy
I especially loved the TASKS you gave. I think it gives you a challenge to test what you have just taught us :) Thanks for taking the time to write this tutorial. It is AWESOME!!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/5/2002 5:15:12 PM:john sheridan
kewl i thought perl was hard, but you explained it well
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/9/2002 5:54:24 PM:Soothe
Good job Ashley! Great content. You may want to use the spelling and grammar checking utility on your word processor. Keep up the good work.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/12/2002 1:39:01 PM:Ted Calbazana
Great Work Ashley! I'd like to see you expand what you've written into a full users guide on learning Pearl. You have a nice easy to read grammatical style! Ever consider a career? Ted
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/28/2002 1:38:11 PM:m0rstis
Sexy article. I must say, however, ignore Soothe and his spell-check and whatnot, Notepad all the way baby! :-D Heh, Soothe, why don't you spell check your Perl while you're at it? :-p
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/30/2002 11:41:07 AM:-Oz
Mort, your just stup!d. Ashley, great tutorial kid! This is one of the best tutorials I have seen for Perl, minus the grammar errors. "A Fast 4 Hour Introduction to Perl" makes perfect sense. Considering of course that most Perl tutorials take up to a month. Great job I say!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/31/2002 6:59:19 PM:
I didnt read the tutorial yet but I have to say that summing up languages in just one article is so difficult,even though if its an introduction. Good work Ashley...btw,I found your post,be patient it takes some time for ppl to recognize the post.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/15/2002 9:29:38 PM:
Thanks for your tutorial. I've known the very basics of PERL for a while, but nothing to help me with any CGI related websites. This tutorial has helped a lot.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
2/27/2003 11:14:51 AM:serpent
amazing....four hours to read....how long to type? you must have put a lot of effort into this thnx. this is 1 of the best on the net
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
2/27/2003 11:26:32 AM:serpent
some of the challenges were hard.... i geuss i caan change carrers now
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
4/4/2003 10:47:20 PM:
Great job, I was wondering if you would give permission to put this on my site... I would give full Credit to you. Email me if you want more people to be lookin at your wonderful tut.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
4/26/2003 10:16:32 AM:John Manavalan
My Dear this is a gr8 work...
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
5/13/2003 4:52:15 AM:
Hey Ashley Thanks for the tutorial, especially liked the challenges you placed at the bottom.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/5/2003 11:57:56 PM:
Excellent beginning introduction to Perl. I carried around a massive tome for a long time and this gets to the heart of the first several chapters in one page. I really needed a refresher course and this reminded me of some of the specifics I needed. The only thing I could think of that might offer easy improvement would be a couple links to tutorials to follow this one.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/9/2003 10:17:17 PM:Paul D
Thank you for your work. What a delightfully easy way to refresh my memory on Perl and CGI in one evening. Beautiful!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/12/2003 1:04:33 AM:Jeff Mills
not a bad tutorial but i don't know where to get the
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/22/2003 12:04:50 AM:Alan Darwish
Ashley, I want to tempt you to work on a project, do you have time?
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
11/16/2003 4:41:42 PM:
Correction. to get user input you would use the following: use CGI; $query=CGI::new(); $name=$query-> param('name'); 'name' would be the name of aan input field on a web page.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this article has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular article, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | Perl Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.