URL addresses only accepts alphanumeric characters and some punctuation symbols, like parenthesis and underscore.
If you need to use any other symbol (like space) you have to URL encode it using a percent sign followed by the two hexadecimal digits that represents that digit in the ASCII table.
For example, the space symbol is character 32 (hexadecimal 20) in the ASCII table, so it's expressed as %20.
In Perl, the easiest way to URL encode a string is to use uri_escape() function from URI::Escape module. This function converts all the unsafe symbols of a string to its URL encode representation.
Use the functions provided by the CGI module. You should define the form with 'start_multipart_form()' and the upload field with 'filefield()'. The file is uploaded to a temporary location; you have to write to another location in order to keep it.
Have a look at the following example to see a working script:
To send the output of die() and/or confess() to the browser, import the CGI::Carp subroutine 'fatalsToBrowser' to your program.
use CGI::Carp qw(fatalsToBrowser);
open(FILE, "nonexistantfile.txt") or die("Can't open file: $!\n");
By default, 'fatalsToBrowser' prints a message at the bottom of the page telling to contact the webmaster; if you want to change that line, you can do it using the 'set_message' routine.
To verify the status of a web site, use the head function from LWP::Simple module.
In scalar context, head returns true if the url passed as a parameter is accessible.
if ( head("http://www.perlhowto.com") )
print "perlhowto.com is running!\n";
print "Oops! site is down\n";
Some special symbols are frequently specified in HTML documents using HTML entities, this entities take the form &name;, like © for the copyright character.
In addition, any character can be specified in HTML in the form of numerical entities, that take the form &#number;, like © for the copyright character.
To convert this kind of HTML data to/from standard characters, you can use the functions 'decode_entities' and 'encode_entities' from HTML::Entities module.
Use the function 'getstore' from the LWP::Simple module. The return value of the function is the HTTP response code.
#-- fetch the zip and save it as perlhowto.zip
my $status = getstore("http://www.perlhowto.com/archive.zip", "perlhowto.zip");
if ( is_success($status) )
print "file downloaded correctly\n";
print "error downloading file: $status\n";
General purpose module for creating web pages
Template Toolkit - excellent template system used primarily for generating dynamic web content
Very useful to fetch web contents
Very helpful module to automate interaction with a website