this variable should be available to other script

If you are brave, and insist on this approach, you can do this with an ugly dot-and-carry method. Assume that your perl script is embedded a wrapper shell (bash-like assumed) script like so:

cd /path/to/script ./myperlscript foo bar rat quux . ./newvar.sh ./myotherscript

Where your perl script 'myperlscript' contains (amongst whatever else it needs to do) something like the following:

#! /usr/local/bin/perl my %new_env = @ARGV; open OUT, '> newvar.sh' or die "cannot open newvar.sh for output: $!\n +"; print OUT "#! /bin/sh\n"; print OUT "export $_=$new_env{$_}\n" for keys %new_env; close OUT;

That is, the perl script writes the shell script that is the next command to be executed in the outer shell script. By the time ./myotherscript runs, the environment will have been sourced by the script that the perl script wrote beforehand.

But keep in mind that this is a maintenance nightmare, and those who come after you will not venerate your name.

- another intruder with the mooring in the heart of the Perl


In reply to Re: create environment variable at run time by grinder
in thread create environment variable at run time by sachin_chat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.