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

How to put variable in cfg file while in another script

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Thanks For any help to enlighten my thick skull.

I have a small script (date.cgi) that comes up with the date of every Sunday. Currently it prints a Scalar variable ($url_date)to screen when executed from my browser.


$url_date = 030501.htm


The idea is to use this variable and concantenate a full url address used in another script(getscriptures.cgi)which finally creates an html doc.The [COLOR=ff0000](getscriptures.cgi)[/color] gets this ($url_date) Scalar variable from a configuration file(scripure.cfg)

My problem is how do I call the(date.cgi) to put this Scalar variable ($url_date) into the configuration file (scripure.cfg) while inside or exiting another cgi named(preview.cgi)

In the begining let us assume there was nothing to begin with. THANX

 
one: you don't need to save it to disk, if you have a proper design, you can pass the value of the variable when you call 'getscriptures.cgi'. the necessary design is that everything has to be modularly built at least as much as having all the vital structures completely contained in subroutines. then, when calling something like &getscriptures::getscript or &date::parse, add '($url_date)' immediately after it (no space). this passes the parameter to the subroutine, which can then access it with a line like "my $url = shift" immediately inside of the subroutine. this works only if the calling script has the line "require file.pl" put in first, and that they're in the same directory (yes, i simplified things a bit).

what would help you the most right now is reading up on programming style and structure.

for records sake, to call another perl script from within your script in an unplanned fasion, this line will do it:[tt]
system "perl otherscript.pl";[/tt]

or replace 'system' with 'exec' if you want that to be the last thing the script does.
this is a shotty solution... much better to have fluid and strong code structure. "If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
I combined the (date.cgi) as a sub inside the (preview.cgi) now have a Scalar variable ($urlselect).

I wrote another sub (sub storeurl) to save the Scalar variable to the (scripure.cfg) file.

The variable is being updated just fine when I examine the (scripure.cfg) file but I keep getting this error "Useless use of a constant in void context at url line 192." in the debugger. I am sure it is being caused by something in this (sub storeurl) addition.


######################
# store $urlselect
#######################
sub storeurl {
$file = $base."/script_config.pm";

open (FILE, ">$file") || die "Can't write to file named $file n";
print FILE<<ENDOFTEXT;
# script_config Part
\$Scripture_url = &quot;$urlselect\&quot;;
ENDOFTEXT
close (FILE, &quot;>$file&quot;) || die &quot;Can't write to file named $file n&quot;;
} #End of storeurl

 
A viable solution seemed to be:

print FILE &quot;# script_config Part\n&quot;;
print FILE &quot;\$Scripture_url = $urlselect&quot;;

instead of the old script, after all it is less code:

print FILE<<ENDOFTEXT;
# script_config Part
\$Scripture_url = &quot;$urlselect\&quot;;
ENDOFTEXT


Just one more question.

Why does there seem to be more problems using
print FILE<<END
scheme as opposed to individual print statements?





 
the problem is not the printing, it's the line:
close FILE, ...
you only need to say
close FILE;
no || or &quot;>file.ext&quot; or anything. &quot;If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top