Solved

Calling a script from html

Posted on 2000-05-07
14
146 Views
Last Modified: 2010-03-05
I am currently learning perl.  I am working with a free script of an auction which seems to be pretty good at teaching how things work.

I can't, for some reason, figure out the proper way to call sections of the perl script from a web page that I create.  I want to eliminate much of the built in html and use my own style and formats.  

How do I do this?  Say I want it to look just like ebay for example.  On my page, I have a table that has 3 columns and 1 row.  I want the categories to appear in the first column along with the number of items next to them.  I have tried several things, and none work.  There must be a way to do this, and any help much appreciated.  I have seen others do exactly what I wish to do, but for some odd reason, they won't reply to my requests for how to do this..

I wasn't sure exactly how much space I could use for the question thus, no code..um...  I as of yet have NO html coded for it, since I wasn't sure how to do this.  I had a friend once that did it once for me, and he knew how, but damned it I can make it work again and can't get hold of him.  

The code is HUGE in the script and as you can imagine, there are however many if then statements for just the stuff you talked about...ie:  

local %form = &get_form_data;
if ($form{'action'} eq 'new') { &new; }
elsif ($form{'action'} eq 'repost') { &new; }
elsif ($form{'action'} eq 'procnew') { &procnew; }
elsif ($form{'action'} eq 'procbid') { &procbid; }
elsif ($form{'action'} eq 'reg') { ® }
elsif ($form{'action'} eq 'procreg') { &procreg; }
elsif ($form{'action'} eq 'creg') { &creg; }
elsif ($form{'action'} eq 'proccreg') { &proccreg; }
elsif ($form{'action'} eq 'closed') { &viewclosed1; }
elsif ($form{'action'} eq 'closed2') { &viewclosed2; }
elsif ($form{'action'} eq 'closed3') { &viewclosed3; }
elsif ($form{'action'} eq 'admin') { &admin; }
elsif ($form{'action'} eq 'procadmin') { &procadmin; }
elsif ($form{'action'} eq 'search') { &procsearch; }
elsif ($form{'item'} eq int($form{'item'}) and $category{$form{'category'}}) { &dispitem; }
elsif ($category{$form{'category'}}) { &displist; }

elsif ($form{'action'} eq 'lp') { &lp; }    #lost password form
elsif ($form{'action'} eq 'lp2') { &lp2; }  # processes lost password

elsif ($form{'action'} eq 'la') { &la; }    #lost alias form
elsif ($form{'action'} eq 'la2') { &la2; }  # processes lost alias

else { &dispcat; }

So, calling the areas isn't impossible.  I know how to edit it to add stuff also, as I have added several of the sections there.  My problem is, in the html coding, I can't remember how to call those sections..  I know I can type in a browser something like:  http://www.mysite.com/cgi-bin/auction.pl?action=lp2    

and that would goto the page for lost passwords..  I can't think of how to do this from within a page though.  Just typing that in shows that.  I can make a link of it also.  But, how do I make that page show up inside another page.  I put it (or want it) to show up inside a table so it is exactly where I want it to be on the page.

If that makes more sense, I would appreciate the help on that.  If not, I guess I am out of luck..  

Thanks for the help in advance...
This link here will take you to a page that I made that hopefully will let you see what I am wanting to do..

http://www.spectrografx.com/moria/index.shtml
Greg
0
Comment
Question by:spectropro
  • 6
  • 6
  • 2
14 Comments
 
LVL 3

Expert Comment

by:guadalupe
Comment Utility
First calling "sections" of a perl script technically speaking is not possible.  However what you could do is call the script with different parameters in the query string which indicate which section of the script is the execute.  Something like this:

http://www.mydomain.com/cgi-bin-myscript.cgi?section=show_table

Then in your script:

#!/usr/bin/perl

&parseInput;


if ($fields eq "show_table")
{
      &show_table;  #Call subroutine show_table
}
elsif ($fields eq "some_other_sub")
{
      &some_other_sub; #Call some other sub!
}
else
{
      #Unknow or default case....
}


#---------------------------------Parse Input---------------------------------------#
#                  Arguments:      NONE                                                                                    #
#                  Purpose            Standard Form/Query String Parsing                                          #
#                  Calls:            NONE                                                                                    #
#-----------------------------------------------------------------------------------#

sub parseInput()
{
      #Parse form variables
      if ($ENV{'REQUEST_METHOD'} eq "POST")
      {
            read(STDIN, $temp, $ENV{'CONTENT_LENGTH'});
      }

      elsif ($ENV{'REQUEST_METHOD'} eq "GET" )
      {
            $temp = $ENV{'QUERY_STRING'};
      }

      @pairs=split(/&/,$temp);
      
      foreach $item(@pairs)
      {
            ($key,$content)=split (/=/,$item,2);
            $content=~tr/+/ /;
            $content=~ s/%(..)/pack("c",hex($1))/ge;
            $fields{$key}=$content;
      }

}



About the table I can't really help with seeing the code and understanding a little better what you want to do.  You talk about displaying data in a certain way but I have no idea where the data is.  Does it come from a database, a flat text file...??  Where is it?  In an array? A Hash?

A little more info and some code would help.

 
0
 
LVL 16

Expert Comment

by:maneshr
Comment Utility
spectropro ,

can you post the perl code you have here?

that way we can provide you with a much more accurate answer.

0
 
LVL 3

Expert Comment

by:guadalupe
Comment Utility
Sorry there was a small error in my code:

if ($fields{'section'} eq show_table")
{
&show_table;  #Call subroutine show_table
}
elsif ($fields'section'}eq "some_other_sub")
{
&some_other_sub; #Call some other sub!
}
else
{
#Unknow or default case....
}

My apologies.
0
 

Author Comment

by:spectropro
Comment Utility
Edited text of question.
0
 

Author Comment

by:spectropro
Comment Utility
Edited text of question.
0
 
LVL 16

Expert Comment

by:maneshr
Comment Utility
Hi Greg,

i looked at http://www.spectrografx.com/moria/index.shtml  page.

Here is my understanding of your requirements.

* you want the index.shtml page to be generated dynamically.
* Also in that page you have a set of categories which should again be hyperlinks to a script (Eg. http://www.mysite.com/cgi-bin/auction.pl?action=categories).

* Now when the user clicks on any category, you want a HTML page to be generated for that category.

* Finally since your index.shtml page itself is dynamic it will be as simple as adding a new category and the hyperlink for that category (with the link to the aution.pl script) will be automatically created.

Pl. let me know if this is indeed the case.

Thanks
0
 

Author Comment

by:spectropro
Comment Utility
maneshr:

hmmm..  Essentially that is correct.  However, I was going to create the front page myself.  And where the list of categories should go, that would be called from the script dynamically.  

Then, when a cat is clicked on, those pages from there on would be created on the fly.  I just can't figure out how in that front page that I will create myself, how to make the script show me the categories without me having to type them in with links to the script.  I want the script to actually post the list of categories..

Thanks.

greg
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 16

Expert Comment

by:maneshr
Comment Utility
here is what i would suggest .

you create the hard-coded html template file by hand. now whereever you want the categories to appear you put some kind of placeholder (Eg <!--dynamic file goes here-->)

Also you have some kind of text file where you would have a list of the categories and the hyperlinks that would go against each category.

Eg.

books|http://wns.com/cgi-bin/auction.pl?cat=books
toys|http://wns.com/cgi-bin/auction.pl?cat=toys

etc...

Finally you have a PERL script that you can run from the command prompt. This script would read the template and when it encounters the placeholder, generate the hyperlinks of categories and put them in a your final html file.

so all that you have to do when you have a new category is add an entry to the text file and run your PERL script!!

let me know your thoughts on the same.
0
 

Author Comment

by:spectropro
Comment Utility
Excellant idea.  I will do that.  Maybe...hehe

Any chance you can lend a hand with the script that would call the text file in??  And if all that is done, how would it call it without human intervention?  Am I looking at having to use a SSI?  Not a problem if so, just currious.
0
 
LVL 16

Accepted Solution

by:
maneshr earned 50 total points
Comment Utility
"Any chance you can lend a hand with the script that would call the text file in??"

sure, let me know you exact requirements.

"And if all that is done, how would it call it without human intervention?"

on a UNIX system you can set up a cron job. the cron job would be triggered automatically at whatever time(s) you want.
on NT systems you can use the task scheduler.

"Am I looking at having to use a SSI? "

no. i would avoid that path to the extent possible!!
0
 

Author Comment

by:spectropro
Comment Utility
Thanks maneshr...  can you please email me directly??

gregs@spectrografx.com
0
 
LVL 16

Expert Comment

by:maneshr
Comment Utility
can you pl. tell me the exact requirements??

that way i know what to code for.

Thanks.
0
 

Author Comment

by:spectropro
Comment Utility
maneshr,   How about I directly email you the script and you will probably understand more of what needs to happen when you see it.  You can mail me at:

gregs@spectrografx.com and I will send the script back to you via email.

Greg
0
 
LVL 16

Expert Comment

by:maneshr
Comment Utility
email me at maneshr@hotmail.com
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now