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

Howdy all you high priests! Anyway, I have been working on a simple CGI perl script so i can leanr how to code - wow, what deep meditation it requires! So, I want to trap anything less than 1 and more than 6000555. At the same time, I also do not want any special characters. So, any number from 1 to the 6000555 is great. So, for the user to see the errors of his ways, it must be printed. So, here are my two problems: 1. How do I get it to go to a frame called "stuff" in a framed website? 2. Here is my code (I know what you all are thinking, but I am a newlie and this is my first attempt). The input is called $patent. What was happening at first is that it would print the error message, but over and over and over. Then I made some changes and now it just spins off into space and the page never loads, just acts like it will. By the way, if I enter a correct nymber, it all works great and the html code at the end prints what I want.
$patent =$value; while (1) { # checking for any non-numeric characters unless ($patent =~ /^[\d]+$/){ print <<ENDERRORCARD; <HTML> <HEAD> <TITLE>Data Entry Error</TITLE> </HEAD> <BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000EE" VLINK="#551A +8B" ALINK="#FF0000"> <CENTER> You either entered a patent number with special characters.<BR> Use your browser's BACK option to try again. </CENTER><P> </BODY> </HTML> ENDERRORCARD next; } last if 1 <= $patent and $patent <= 6009555; print <<ENDERRCARD; <HTML> <HEAD> <TITLE>Data Entry Error</TITLE> </HEAD> <BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000EE" VLINK="#551A +8B" ALINK="#FF0000"> <CENTER> You entered a patent number that was not between 1 and 6,009,555.< +P> Use your browser's BACK option to try again. </CENTER><P> </BODY> </HTML> ENDERRCARD } # This compares the patent number of the user against US patent number + dates

Replies are listed 'Best First'.
(Ovid) Re: HTML error routine
by Ovid (Cardinal) on Dec 13, 2001 at 05:58 UTC
    How do I get it to go to a frame called "stuff" in a framed website?

    We don't have enough code to know everything that you're doing, but here's a start. Assuming that you are using CGI.pm:

    #!/usr/bin/perl -wT use strict; use CGI qw/:standard/; # use this where you would ordinarily have # print "Content-Type: text/html\n\n"; print header( -target => 'stuff' ); my $_patent = param( 'patent' ); # see 'perldoc perlsec' # $patent is set to digits or zero my ( $patent ) = ( $_patent =~ /^(\d+)$/ ) || 0; if ( $patent < 1 or $patent > 6000555 ) { send_error_page(); } else { # patent number is good, let's process it } sub send_error_page { print <<ENDERRORCARD; <HTML> <HEAD> <TITLE>Data Entry Error</TITLE> </HEAD> <BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000EE" VLINK="# +551A8B" ALINK="#FF0000"> <CENTER> Patent number must be a number between 1 and 6000555, inclusiv +e.<BR> Use your browser's BACK option to try again. </CENTER><P> </BODY> </HTML> ENDERRORCARD }

    If you're not sure what I'm doing with the regular expression, please read perlsec.

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Re: HTML error routine
by Anonymous Monk on Dec 13, 2001 at 15:41 UTC
    Howdy!

    First of all, thanks.

    I have been scanning through numerous discussions here in scared halls of Perl wisdom. I see lots of code that uses such things (I am new) as CGI.pm. So, I must ask this question - how do I know if my Server has it and if not what do I do then? In fact, what else might my Server have that I can be learning to use to make coding easier?

    I am thinking that if I am doing a script for a website, that there must be a script that tests the Server to see what they have available - or is that wishful thinking?

    Bill

    lupun auribus teneo (I have a wolf by the ears)