×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How to put variable in cfg file while in another script

How to put variable in cfg file while in another script

How to put variable in cfg file while in another script

(OP)
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 (getscriptures.cgi) 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

RE: How to put variable in cfg file while in another script

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:
system "perl otherscript.pl";

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."

RE: How to put variable in cfg file while in another script

(OP)
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 = "$urlselect\";
ENDOFTEXT
close (FILE, ">$file") || die "Can't write to file named $file n";
} #End of storeurl

RE: How to put variable in cfg file while in another script

(OP)
A viable solution seemed to be:

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

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

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


Just one more question.

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





RE: How to put variable in cfg file while in another script

the problem is not the printing, it's the line:
close FILE, ...
you only need to say
close FILE;
no || or ">file.ext" or anything.

"If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close