Accessing a variable in one perl script from the other

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • learnPHP
    New Member
    • Mar 2008
    • 20

    Accessing a variable in one perl script from the other

    Hi,

    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.

    Thanks
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    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.

    Comment

    • Icecrack
      Recognized Expert New Member
      • Sep 2008
      • 174

      #3
      Kevin is correct in many ways.


      try:

      running the second perl script by:

      First Script:
      Code:
      system("perl script.pl $p");

      Second Script:
      Code:
      foreach (@ARGV) { 
      $p=@ARGV[0];
      }

      this is untested but may work.

      Comment

      Working...