By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,178 Members | 987 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,178 IT Pros & Developers. It's quick & easy.

Accessing a variable in one perl script from the other

P: 20

I am completely new to Perl. I am trying to access a variable in one of my Perl scripts from a 2nd perl script.

The 1 st script uses a file and extracts some data and manipulates the data and assigns the variable $p with some value.

Now after the 1 st script has been executed I want the value of $p in my 2nd script. Is that possible?? Please let me know how to access this value of $p.

Sep 30 '08 #1
Share this Question
Share on Google+
2 Replies

Expert 2.5K+
P: 4,059
If script one runs and ends, then you run script two, the values in script one are gone. You would have to write them to disk, text file or database, to make them persistent. Otherways to include external perl scripts in your script is via "do" or "require". You can look those up in the perl documentation.
Sep 30 '08 #2

Expert 100+
P: 174
Kevin is correct in many ways.


running the second perl script by:

First Script:
Expand|Select|Wrap|Line Numbers
  1. system("perl $p");

Second Script:
Expand|Select|Wrap|Line Numbers
  1. foreach (@ARGV) { 
  2. $p=@ARGV[0];
  3. }

this is untested but may work.
Sep 30 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.