Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
575 views
in Technique[技术] by (71.8m points)

html - How to access variable of other perl program in my perl program

I have three different Perl programs. I want to access the value of a variable present in the first program in the other two Perl programs.

My first Perl program look like the following:

#!/usr/bin/perl
print "Content-Type: text/html; charset=utf-8

";

use CGI;
use Cwd;
use utf8;
$q=new CGI;
$a=$q->param('file');
#chomp($a);
my $ftpname="$a";

This program takes value from a text of HTML program. I need the value of the $ftpname variable in my other to Perl programs. How can I do that?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There can be more than one way to solve your problem.

  1. You can save the value of $a in a text file and then read that text file in your other two programs.
  2. You can create a module that contains functions to act upon the value of $a. Then you can call the proper moduleName::functionName with $a as argument. A simple tutorial to get you started would be here.
  3. If you want to share variables anyway, you can have a module that acts as some sort of header file with the variable declarations (using the our keyword and/or exporting), and then this module is used in all of your other perl scripts and the variable is visible everywhere. See this answer. For more help on variable scope, you may read this reference: Coping with Scoping

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...