Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a perl script that access's several other perl scripts sequentially. I'm kind of new to perl.. any idea's on how to keep a variable from the first script available to subsequent scripts accessing the first script?

Thanx... Lisa.

Edited 2002-08-05 by Ovid

Replies are listed 'Best First'.
Re: Keeping variable persistent
by DamnDirtyApe (Curate) on Aug 05, 2002 at 23:35 UTC

    One option might be to pass the variables as command-line parameters.

    test_q.pl
    #! /usr/bin/perl use strict ; use warnings ; $|++ ; my $arg_one = 'foo' ; my $arg_two = 'bar' ; my $arg_three = 'zoot' ; system 'perl', './test_r.pl', $arg_one, $arg_two, $arg_three ; exit ; __END__
    test_r.pl
    #! /usr/bin/perl use strict ; use warnings ; $|++ ; my ( $arg_one, $arg_two, $arg_three ) = @ARGV ; print "Arg one is $arg_one.\n" ; print "Arg two is $arg_two.\n" ; print "Arg three is $arg_three.\n" ; exit ; __END__

    _______________
    DamnDirtyApe
    Those who know that they are profound strive for clarity. Those who
    would like to seem profound to the crowd strive for obscurity.
                --Friedrich Nietzsche
Re: Keeping variable persistent
by Ovid (Cardinal) on Aug 05, 2002 at 23:39 UTC

    Could you post some code? What do you mean by "accesses several other perl scripts sequentially"? Are you using system? Are you using the special form of do? Are you actually just running some Perl scripts sequentially for which a shared data file might be an appropriate solution?

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

       >>Are you actually just running some Perl scripts sequentially for which a shared data file might be an appropriate solution?
      
      Yess.. the first script access's the second script..
      and so on.. i need a variable from the first script
      to be available to the last script.. but from what
      ive seen so far.. variables dissapear when the script
      pertaining to that variable has finished running.
      So i don't need to share a data file.. just keep a
      variable from the first script alive, or available 
      for the last script. 
Re: Keeping variable persistent
by Anonymous Monk on Aug 06, 2002 at 01:56 UTC
    # Parent script $ENV{FOO} = "Hello, world\n"; # Child script print $ENV{FOO};
    But don't do that.

    Instead learn how to write functions and libraries, and then learn why globals are officially a Bad Idea.