CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Perl validation program

 



mwaf
Deleted

Jun 14, 2000, 8:30 AM

Post #1 of 4 (325 views)
Perl validation program Can't Post

I know this isn't really the place for this topic but I didn't find any suitable as General is for none-perl/programming stuff.

Anyway, is there any Perl validation program or webpage? I would at least want to know on which line the error is.

It's very frustrating (as probably everyone knows, at least those how has done anything else than HTML, which won't mind errors too much, BTW, I hate doing WML, if you've have <br> instead of <br/> the whole page collapses Frown) when you've just done lots of new code and the script won't work. You search for the error in your newly done code and the error is just that you've by mistake somewhere else written:
prnit "$whatever";


Kanji
User / Moderator

Jun 14, 2000, 11:00 AM

Post #2 of 4 (325 views)
Re: Perl validation program [In reply to] Can't Post

You can invoke perl in-built syntax checker with -c switch:
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

$ cat script.pl
#!/usr/bin/perl
prnit "This should cause an error\n";
$ perl -c script.pl
String found where operator expected at script.pl line 2, near "prnit "This should cause an error\n""
(Do you need to predeclare prnit?)
syntax error at script.pl line 2, near "prnit "This should cause an error\n""
script.pl had compilation errors.</pre><HR></BLOCKQUOTE>

Also, I strongly advise regularly using perl's -w switch (and use strict; for that matter) which catches many silly errors.

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

$ cat script.pl
#!/usr/bin/perl -w
prnit "This should cause an error\n";
$ ./script.pl
Unquoted string "prnit" may clash with future reserved word at ./script.pl line 2.
String found where operator expected at ./script.pl line 2, near "prnit "This should cause an error\n""
(Do you need to predeclare prnit?)
syntax error at ./script.pl line 2, near "prnit "This should cause an error\n""
Execution of ./script.pl aborted due to compilation errors.</pre><HR></BLOCKQUOTE>

Programming with -w on takes some getting used to though as it can be really fussy. :-)


mwaf
Deleted

Jun 14, 2000, 11:57 AM

Post #3 of 4 (325 views)
Re: Perl validation program [In reply to] Can't Post

Can't get this to work: 'Premature end of script headers', which it almost always says when I've done any error in the code.

I tried these:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

$ cat script.pl
#!/usr/bin/perl -w
print "Content-type:text/html\n\n";
print "This should cause an error\n";
$ ./script.pl</pre><HR></BLOCKQUOTE>

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

$ cat script.pl
#!/usr/bin/perl
print "Content-type:text/html\n\n";
print "This should cause an error\n";
$ perl -c script.pl</pre><HR></BLOCKQUOTE>

(and both also with the uncorrect version (...prnit "...)

...and I had the script file named, script.pl and I uploaded as ASCII and all that stuff.


Kanji
User / Moderator

Jun 14, 2000, 12:56 PM

Post #4 of 4 (325 views)
Re: Perl validation program [In reply to] Can't Post

'Premature end of script headers' happens when you output data before any HTTP headers.

In the example you give, your problem lies with print "Content-type:text/html\n\n";, which should be print "Content-Type: text/html\n\n"; (the T in Type and the addition of a space after Smile.

This isn't a problem with your perl script, but your compliance (or lack thereof) of HTTP/CGI standards.

Essentially, if it works on the command line (via a shell) then the problem is most likely with your logic and/or program, rather than syntax, and you won't find any validators for that.

As a side-note, if you aregoing to debug via CGI, then take a look at CGI::Carp, particularly the carpout and fatalsToBrowser methods.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives