I am not entirely sure I get what you are trying to do, but see inline.

Ebaad Ahmed wrote:
Hello everybody,

I would like to include a file in my cgi code so that it contains all the lists of data, and later can be edited from another form to create an admin tool for the lists in the main form.
If you are just talking about a list of data, then it can be stored either as actual perl code or as a just text delimited by something (most likely new lines). In the case of using perl code, you could just declare it as an array like in any script, note that it will have to be a global which would make strict complain and this is not a good way to do anything but a one-off.


I have researched alot and found that I can use "require" or "use" for this purpose
but I still could not find a complete simple example of how to declare the array in an external file and how to recall the data from the cgi script in order to display it.

If you still want to take this approach of having the data stored as a perl structure the easiest way would be to store it lexically in the file as an array for instance, then write a quick subroutine to return either the array itself, or a reference to the array. For example:

our @data = ('element1','element2','element3');

sub return_data {
return @data;
}

or

sub return_data_as_array_ref {
return \@data;
}

And then in your other script you would simply say:

require 'data_file.pl';
@local_copy_of_data = return_data();

or

$local_ref_to_data = return_data_as_array_ref();


Any help will be greatly appreciated.

However if it is just a list of data, you might consider just storing it one element per line, then using 'open' to open the file and then read it into an array or line by line.

my $HANDLE;
open($HANDLE,'/path/to/file_with_data.txt') or die "Can't open data file: $!";
my @data = <$HANDLE>;
close($HANDLE);

In both cases to edit the file you will have to do an open and the print the contents into the file either manually doing your formatting if any is required or using something like Data::Dumper or XML, etc.

good luck,

http://danconia.org


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to