Solved

Calling a script from html

Posted on 2000-05-07
14
152 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
  • 2
14 Comments
 
LVL 3

Expert Comment

by:guadalupe
ID: 2788388
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
ID: 2788514
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
ID: 2788591
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:spectropro
ID: 2790594
Edited text of question.
0
 

Author Comment

by:spectropro
ID: 2790731
Edited text of question.
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2792402
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
ID: 2794340
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
 
LVL 16

Expert Comment

by:maneshr
ID: 2794430
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
ID: 2794845
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
ID: 2796605
"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
ID: 2798098
Thanks maneshr...  can you please email me directly??

gregs@spectrografx.com
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2800195
can you pl. tell me the exact requirements??

that way i know what to code for.

Thanks.
0
 

Author Comment

by:spectropro
ID: 2802212
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
ID: 2802306
email me at maneshr@hotmail.com
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…

749 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