Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 20th, 2008, 01:51 PM
dipgi dipgi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2008
Posts: 5 dipgi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 36 m 16 sec
Reputation Power: 0
Showing perl output in html

hi i am new to perl programming. My problem is i have a perl program which takes a input from user and generate some outputs. Now i want to do it through a html page. The page can take some input from user and pass it to the perl program and show the output in the page itself. Can anyone please suggest me some way to do it with some simple code example. I know it is a very novice question but i really need some help.
thanks in advance.

Reply With Quote
  #2  
Old September 20th, 2008, 03:22 PM
keath's Avatar
keath keath is offline
!~ /m$/
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: May 2004
Location: Reno, NV
Posts: 4,086 keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 6 h 59 m 11 sec
Reputation Power: 1809
Code:
#!/usr/bin/perl -wT
use strict;

use CGI qw/:standard/;

my $q = CGI->new;
my $name = $q->param('name');

print header, start_html('Form Test');

if ($name) {
	print p("Hello $name");
} else {
	print start_form, 
	'Enter your name', br,
	'Name: ', textfield('name'), br,
	submit, end_form;
}
print end_html;

Reply With Quote
  #3  
Old September 21st, 2008, 09:43 AM
dipgi dipgi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2008
Posts: 5 dipgi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 36 m 16 sec
Reputation Power: 0
thanks keath for your example. But now have another problem. whenever i try to run the script from web browser it only shows the script itself. I figured it out it is about some apache server configuration about cgi script folder. In unix system i am using public_html folder under my user directory to put my html files. I explored a bit and find out httpd.conf file contains the entry ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" which shld direct me to the correct cgi-bin directory. Can u plz suggest me a way to make my webservice detect my cgi files. thanks.

Reply With Quote
  #4  
Old September 21st, 2008, 10:34 AM
keath's Avatar
keath keath is offline
!~ /m$/
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: May 2004
Location: Reno, NV
Posts: 4,086 keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 6 h 59 m 11 sec
Reputation Power: 1809
You simply have to move the file into the /var/www/cgi-bin/ directory. The configuration tells Apache that files in that directory should be executed rather than merely displayed.

Reply With Quote
  #5  
Old September 21st, 2008, 10:38 AM
dipgi dipgi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2008
Posts: 5 dipgi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 36 m 16 sec
Reputation Power: 0
yes, but the problem is there are lots of other users accessing the same server and i dont have access permission to /var/www/cgi-bin/. I have only access to my own account files. There must be a way by which individual user should access and run there cgi files from their local directory, isnt it ?

Reply With Quote
  #6  
Old September 21st, 2008, 10:57 AM
keath's Avatar
keath keath is offline
!~ /m$/
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: May 2004
Location: Reno, NV
Posts: 4,086 keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 6 h 59 m 11 sec
Reputation Power: 1809
It's interesting that you can see the Apache configuration file, but not have access to that directory.

Apache can serve executable files from other directories if it is set up to do so. I couldn't guess which directory that is though. You will have to ask your administrator.

Reply With Quote
  #7  
Old September 23rd, 2008, 02:25 PM
dipgi dipgi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2008
Posts: 5 dipgi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 36 m 16 sec
Reputation Power: 0
Keath, i finally got the access and now I can run the scripts. now i have another problem with "Insecure $ENV{PATH}" while i am trying to execute the following line of code,
my $result = `ts-query -d $kb -f ascii "$query"`;
It works fine with my perl program but not when i am trying to execute it through browser.
I explore the net and found out that i need to set the following lines or something like that,
$ENV{’PATH’} = ’/bin:/usr/bin’;
delete @ENV{’IFS’, ’CDPATH’, ’ENV’, ’BASH_ENV’};

But now i am getting the error that s:ts-query:command not found.
Further my cgi-bin directory is /var/www/cgi-bin and home dir is /home/<username>/
Please can anyone help me on how to run my query ?
thanks

Reply With Quote
  #8  
Old September 23rd, 2008, 06:06 PM
keath's Avatar
keath keath is offline
!~ /m$/
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: May 2004
Location: Reno, NV
Posts: 4,086 keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 6 h 59 m 11 sec
Reputation Power: 1809
Since you nulled out the command paths, you need to provide the full path to wherever your commands are located. Example:
`/usr/bin/ts-query`;

Reply With Quote
  #9  
Old September 24th, 2008, 06:33 AM
dipgi dipgi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2008
Posts: 5 dipgi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 36 m 16 sec
Reputation Power: 0
That worked perfectly and now i can see my results.. thanks a lot keath for your time

Reply With Quote
  #10  
Old November 7th, 2008, 08:08 AM
ravi1987 ravi1987 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2008
Posts: 1 ravi1987 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 5 sec
Reputation Power: 0
Quote:
Originally Posted by keath
Code:
#!/usr/bin/perl -wT
use strict;

use CGI qw/:standard/;

my $q = CGI->new;
my $name = $q->param('name');

print header, start_html('Form Test');

if ($name) {
	print p("Hello $name");
} else {
	print start_form, 
	'Enter your name', br,
	'Name: ', textfield('name'), br,
	submit, end_form;
}
print end_html;


i am actually new to all this now i want to give input to perl variable in html and want html to execute the perl code and dispaly output in same window, i want to do in windows .now what all do i need 2 in stall and how to proceed with the same.please help me its urgent .........

Reply With Quote
  #11  
Old November 7th, 2008, 07:47 PM
theNbomr theNbomr is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Location: BC, Canada
Posts: 39 theNbomr User rank is Sergeant (500 - 2000 Reputation Level)theNbomr User rank is Sergeant (500 - 2000 Reputation Level)theNbomr User rank is Sergeant (500 - 2000 Reputation Level)theNbomr User rank is Sergeant (500 - 2000 Reputation Level)theNbomr User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 22 h 51 m 16 sec
Reputation Power: 12
CGI is very clear about how to pass values to the script. As keath has demonstrated, you use the CGI module's param() method to get data from your HTML form.
HTML does not execute your perl code; either the perl compiler/interpreter or the mod-perl module runs your perl code as a child process of the web server. Your perl code is responsible for generating the HTML that is to appear in the browser window. Once again, the perl CGI module provides all of the tools you need to do this. It is also possible to embed some HTML directly into your perl script, and then print it. The code snippet supplied by keath demostrates this, as well.
The good news is, if you have a working perl CGI access, that should be all you need. Nothing to install except the code you write.
--- rod.

Reply With Quote
  #12  
Old November 9th, 2008, 06:38 PM
Axweildr's Avatar
Axweildr Axweildr is offline
'fie' on me, allege-dly
Click here for more information.
 
Join Date: Mar 2003
Location: in da kitchen ...
Posts: 12,874 Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)  Folding Points: 162285 Folding Title: Super Ultimate Folder - Level 1Folding Points: 162285 Folding Title: Super Ultimate Folder - Level 1Folding Points: 162285 Folding Title: Super Ultimate Folder - Level 1Folding Points: 162285 Folding Title: Super Ultimate Folder - Level 1Folding Points: 162285 Folding Title: Super Ultimate Folder - Level 1Folding Points: 162285 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 4 Months 2 Weeks 1 Day 20 h 28 m 56 sec
Reputation Power: 6421
Send a message via Google Talk to Axweildr
Orkut
code is run, not installed, just the way it is ...
__________________
--Ax
without exception, there is no rule ...
Handmade Irish Jewellery
Targeted Advertising Cookie Optout (TACO) extension for Firefox
The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones


09 F9 11 02
9D 74 E3 5B
D8 41 56 C5
63 56 88 C0
Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.
-- Jamie Zawinski
Detavil - the devil is in the detail, allegedly, and I use the term advisedly, allegedly ... oh, no, wait I did ...
BIT COINS ANYONE

Reply With Quote
  #13  
Old November 17th, 2012, 08:37 PM
Avariuttill Avariuttill is offline
Permanently Banned
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Location: Yugoslavia
Posts: 1 Avariuttill User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 48 sec
Warnings Level: 10
Number of bans: 1
Reputation Power: 0
Send a message via ICQ to Avariuttill
http://www.fanaticscustom.com/chris+rainey+jersey-c-2557_2963_3088.html Ontonyday

lestteestiari URLURLURL

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Showing perl output in html

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap