#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2008
    Posts
    5
    Rep 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.
  2. #2
  3. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,264
    Rep Power
    1810
    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;
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2008
    Posts
    5
    Rep 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.
  6. #4
  7. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,264
    Rep Power
    1810
    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.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2008
    Posts
    5
    Rep 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 ?
  10. #6
  11. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,264
    Rep Power
    1810
    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.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2008
    Posts
    5
    Rep 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
  14. #8
  15. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,264
    Rep Power
    1810
    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`;
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2008
    Posts
    5
    Rep Power
    0
    That worked perfectly and now i can see my results.. thanks a lot keath for your time
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2008
    Posts
    1
    Rep Power
    0
    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 .........
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Location
    BC, Canada
    Posts
    39
    Rep Power
    13
    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.
  22. #12
  23. 'fie' on me, allege-dly
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2003
    Location
    in da kitchen ...
    Posts
    12,894
    Rep Power
    6444
    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
  24. #13
  25. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Yugoslavia
    Posts
    1
    Rep Power
    0

    http://www.fanaticscustom.com/chris+rainey+jersey-c-2557_2963_3088.html Ontonyday



IMN logo majestic logo threadwatch logo seochat tools logo