Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Perl

Can anyone suggest a way to check from a Perl script if a particular file exists on the server?

Use this bit of code:

if(-e $file){
# file exists!
}

Can anyone recommend any good software for debugging Perl/cgi? Also, where can I find a complete reference to all Perl variables.

Be sure to execute the script with the -w flag...this will display error messages. This works if you're using the command line; if it's going to a browser, put a 'use Carp qw(:FatalsToBrowser);' (and be sure to check the syntax on this). Also, you could use something like this in scripts when an error could occur:

$cgi->print_error("Please go $back_link 
and reply to these questions: 
<ul>$errors</ul>",\%mail) if @error;

$rc = $sth->execute || $cgi->print_error("Major 
programming error has occurred and the programmer 
has just been notified",\%mail);

This sends the error to the screen in a nicely formatted way (and provides a form or email for them to complain) and it also sends me an email telling me of the error.

For the second part of the question: More than everything you ever wanted to know about Perl can be found online at CPAN. This is the 'Comprehensive Perl Archive Network' and has all the docs, modules, source, etc. Also be sure to check the WDVL's own Perl section.

Does anyone know how to call a Perl Script using Javascript?

I use a <form> to make the name-value-pairs I like to send to the Perl script, then I use the JavaScript submit() method when I like to call the Perl script. When you use this you don't have to have a submit button at all.

Is there a way to see what variables and values a form is passing to a Perl Script?

Of course be sure you are using CGI.pm. No reason to re-invent the wheel unless you can improve on it. The following code makes it much easier to read, understand, and modify:

use CGI;
my $q = CGI->new();
my $debug = 0;

print $q->header;
print $q->dump if $debug;

The dump function will return all the values sent from your form (formatted in bullet style). I use $debug as I am writing a script and I change its value if I want to see what is going on behind the scenes.

How do I generate random numbers in Perl?

First, seed the random number generator:

srand;

Then write a function to return a random number:

sub rand_num{ int(rand $_[0]) + $_[1] }

Then use it:

$random_number = &rand_num(1, 10); 
# 1 is minimun, 10 is the max


Up to => Home / WDVL / Forum




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers