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: Intermediate:
NEED HELP QUICK PLEASE

 



theworkz
Deleted

Jun 1, 2000, 8:12 AM

Post #1 of 5 (978 views)
NEED HELP QUICK PLEASE Can't Post

hello, I need some quick help on a script.. It is a jump script but i have put a text input for people to type their zipcode in and it redirects them to a page designated to that zipcode.. What i need is, a line somewhere in the perl script to goto an error.html file if the zipcode isnt found. Here is the script..
------------------------------
#!/usr/bin/perl

require("cgi-lib.cgi");
&ReadParse;

open(FILEHANDLE,"<zipdata.list");
while($line = <FILEHANDLE> )
{
$line =~ s/\n//g;

($product,$goto) = split(/\|/, $line);
if($product eq $in{'jump'})
{
close FILEHANDLE;
print "Location: $goto\n\n";
exit;
}

}
-----------------------------------
Here are the lines that the data is pulled from..

97220|http://www.whatever.com/whatever.html


I really need help on this so if there is anyway for the script to send the user to an error page when the incorrect zip is put in.. PLEASE LET ME KNOW ASAP.. THANK YOU in advance..

Luke Ross


monocle
User

Jun 1, 2000, 12:23 PM

Post #2 of 5 (978 views)
Re: NEED HELP QUICK PLEASE [In reply to] Can't Post

No promises but try this rewrite to your script. If you pre load the $goto with the error.html and the script does not find a replacement for this, the user will be sent to the error.html.
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


#!/usr/bin/perl

require("cgi-lib.cgi");
&ReadParse;

$goto = "http://www.whatever.com/error.html";
open(FILEHANDLE,"<zipdata.list");
while($line = <FILEHANDLE> ){
$line =~ s/\n//g;
($product,$url) = split(/\|/, $line);
if($product eq $in{'jump'}){
$goto = $url;
last;
}
}
close FILEHANDLE;
print "Location: $goto\n\n";
exit;
</pre><HR></BLOCKQUOTE>

Monocle
Hear techno music by Monocle at http://www.mp3.com/monocle

[This message has been edited by monocle (edited 06-01-2000).]


perlkid
stranger

Jun 1, 2000, 3:03 PM

Post #3 of 5 (978 views)
Re: NEED HELP QUICK PLEASE [In reply to] Can't Post

 
I also agree with monocle,

But I have a question for monocle,

Why do you you last; in this code. What's it for here. Is it just to skip everything else when it finds match?

perlkid


theworkz
Deleted

Jun 2, 2000, 8:08 AM

Post #4 of 5 (978 views)
Re: NEED HELP QUICK PLEASE [In reply to] Can't Post

Thanks everyone for your help.. all i had to do was add this line at the end of the code.


print "Location: http://www.whatever.com/whatever.shtml\n\n";

Worked great...

THANKS ALL

Luke


monocle
User

Jun 2, 2000, 11:11 AM

Post #5 of 5 (978 views)
Re: NEED HELP QUICK PLEASE [In reply to] Can't Post

perlkid,

you are correct. it can speed things up if you have a large amount of lines. say you match on like the third line out of one thousand, no need to keep stepping through all the rest when you know you have a match.

 
 


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

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