Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to include a per script?

Status
Not open for further replies.

PaulOtten

Programmer
Joined
Jan 13, 2006
Messages
2
Location
NL
Hi,

I've tried to load a perlscript within a perlscript like so:
require "../html/test.cgi?ID=12345";
It doesn't work. Is there a solution for loading a perlscript with a variable.

Thanks,
 
The script you're trying to call is obviously CGI and yet you're trying to call it as though it were a library.
CGI scripts are designed to be called by the webserver, not your code.
Why don't reconsider what you're actually trying to do?
Maybe you should be calling the webserver itself with something like or maybe you should consider extracting the functionality you want from that CGI script and put it into a separate module that you CAN "use" or "require".
Without knowing what that particular script is supposed to do and what you are trying to do I don't think I can help much more.


Trojan.
 
The script prints the Top of a HTML, including a Menu structure. I have about 20 scripts witch will have to print the same Top. If I change something in the menu, I only have to change it in one script, not in 20.

I would like to send a variable so people can see witch menu item is selected. I hope you know what i mean.

Thanks again,
 
Consider learning how to use HTML::Template. Mixing your HTML directly into your Perl code is always going to be awkward. With a templating system, your HTML is kept seperately and perl fills in whichever values are dynamic. You'll still only have to edit only one "header", "footer" or "menu" template whenever you need to make alterations, which helping your seperation of code and layout.
 
why don't you plase the code in your test.cgi inside a subroutine like
Code:
your test.cgi now:

$foo = $cgi->param('ID');  #or whatever your way of getting the ID
line 1
line 2
line 3
line 4


your test.cgi after:

$foo = $cgi->param('ID');
&print_id($foo)

sub print_id 
{
    my $foo = @_;
    line 1
    line 2
    line 3
    line 4
    ..........
    ..........
}

and at you main script
Code:
require "../html/test.cgi";
&print_id($my_id);
line 3
line 4
........




or even better... do you know the hash?
example:
Code:
template.cgi:


%template=(
             'header'=>qq{<html>
                           <head>
                            <title>My title</title>
                             <body>
                              <table>
                          },
             
              'form' =>qq{					                          <tr>
                           <td>First Name:</td>
                           <td><input type="text" name="FirstName" value="$FirstName"></td>
                          </tr>
                          <tr>
                           <td>Last Name:</td>
                           <td><input type="text" name="LastName" value="$Lastname"></td>
                          </tr>
                          },

               'footer' =>qq{
                          <input type="submit" name="submit" value="submit">
                         </table>
                       </body>
                     </html>
                             }
              );
1;

your current script:
Code:
#!/usr/bin/perl

require("template.cgi");

$query = new CGI;
print $cgi->header;
print $template{'header'};

if the guy is already registered and he has a name then search the database found them.
put them inside two variables
$FirstName, $LastName
and then

print $template{'form'};

the fields will be already filled. If he is not registerd then they will be empty cause inside $FirstName, $LastName there is nothing

print $template{'footer'};

exit 0;

i hope i gave a clue............


``The wise man doesn't give the right answers,
he poses the right questions.''
TIMTOWTDI
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top