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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Including info, and search/change

Status
Not open for further replies.

Archon

Programmer
May 1, 2001
17
0
0
US
I've been working w/ Perl for less than a week and I have 2 quick, seemingly simple, questions:

First, I've included header files already, but how do I include another .cgi file if I want to use values it has retreived? If that's not clear... I'm writing a program that needs to use elements from another .cgi, how do I include/call them?

Second, if I've thrown a data file into an array as @raw_data so I could process it a few different ways, is there a quick and easy way to search this for " and change them to ' ?

Thanks
 
I'm still not certain what you're trying to achieve with your first question, but here's a shot. The do function, when given a single argument, evaluates that argument as a file then executes it, returning the value from the last line in the script (at least, I think this is how it works.. check the perldocs for more information).

As far as the second item goes, you can do this with a simple foreach loop and substitution.
Code:
foreach(@array) {
    $_=~s|"|'|g;
}

Hope this helps,

brendanc@icehouse.net
 
You might want to look at the documentation for modules, that may be what you need. Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Great, Thanks. Second problem is taken care of. Let me try to rephrase my first question and see if there's anything you might suggest.

I'm writing an extension to a larger .cgi program. The small part that I'm writing now will require variable values and data from the larger program. I dont' know how to, in perl, include those variables in my program, so that I may use those and the subroutines from the larger program as I need them.

Example: The original program reads in a list of registrants for an upcoming event. Say this is just stored in @registrants. Do I need to include the name of this file somehow to use @registrants in MY program?

Let me know if this makes more sense. Basically I'm asking how to pass parameters between .cgi files in the same directory.

Thanks
 
Try:
Code:
require "program.pl";
This will include all of the code from the file "program.pl" in your program, including subroutine and variable definitions.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Archon,

You need to have a look at the use of modules (packages) in Perl.

It may be that you will need to alter the structure of your original Perl script so that you can make some of the data available to other scripts. I'm sure you'll have seen statements like this in some scripts.

use Net:SMTP;

This means that the current script is using the Net::SMTP module and is able to use some stuff (procedures mostly in this case, but modules can make data available as well) from the SMTP module.

Could I suggest that you follow this course for the moment:

1 - Read up on modules.

2 - Identify which subroutines and variables you will need to share between perl scripts.

3 - Move those subroutines and variables to a separate module.

4 - Use the new module in your original CGI program, get this working well before you go any further.

5 - Then look at your new script(s)
Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top