The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Perl Programming
|
Showing perl output in html
Discuss Showing perl output in html in the Perl Programming forum on Dev Shed. Showing perl output in html Perl Programming forum discussing coding in Perl, utilizing Perl modules, and other Perl-related topics. Perl, the Practical Extraction and Reporting Language, is the choice for many for parsing textual information.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

September 20th, 2008, 01:51 PM
|
|
Registered User
|
|
Join Date: Sep 2008
Posts: 5
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.
|

September 20th, 2008, 03:22 PM
|
 |
!~ /m$/
|
|
Join Date: May 2004
Location: Reno, NV
|
|
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;
|

September 21st, 2008, 09:43 AM
|
|
Registered User
|
|
Join Date: Sep 2008
Posts: 5
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.
|

September 21st, 2008, 10:34 AM
|
 |
!~ /m$/
|
|
Join Date: May 2004
Location: Reno, NV
|
|
|
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.
|

September 21st, 2008, 10:38 AM
|
|
Registered User
|
|
Join Date: Sep 2008
Posts: 5
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 ?
|

September 21st, 2008, 10:57 AM
|
 |
!~ /m$/
|
|
Join Date: May 2004
Location: Reno, NV
|
|
|
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.
|

September 23rd, 2008, 02:25 PM
|
|
Registered User
|
|
Join Date: Sep 2008
Posts: 5
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
|

September 23rd, 2008, 06:06 PM
|
 |
!~ /m$/
|
|
Join Date: May 2004
Location: Reno, NV
|
|
|
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`;
|

September 24th, 2008, 06:33 AM
|
|
Registered User
|
|
Join Date: Sep 2008
Posts: 5
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 
|

November 7th, 2008, 08:08 AM
|
|
Registered User
|
|
Join Date: Nov 2008
Posts: 1
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 .........
|

November 7th, 2008, 07:47 PM
|
|
Contributing User
|
|
Join Date: May 2008
Location: BC, Canada
|
|
|
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.
|

November 9th, 2008, 06:38 PM
|
 |
'fie' on me, allege-dly
|
|
Join Date: Mar 2003
Location: in da kitchen ...
|
|
|
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
Deta vil - the devil is in the detail, allegedly, and I use the term advisedly, allegedly ... oh, no, wait I did ...
BIT COINS ANYONE
|

November 17th, 2012, 08:37 PM
|
|
Permanently Banned
|
|
Join Date: Nov 2012
Location: Yugoslavia
Posts: 1
Time spent in forums: 27 m 48 sec
Warnings Level: 10
Number of bans: 1
Reputation Power: 0
|
|
|
http://www.fanaticscustom.com/chris+rainey+jersey-c-2557_2963_3088.html
Ontonyday
lestteestiari URLURLURL
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|