also this variable should be available to other script where this env variable is used .

This isn't possible in a straightforward way, as brian_d_foy mentioned. The reason lies in the way environment variables work. Environment variables belong not to a user, or to a "login session," but to a process. Any child process of that process then inherits those variables. So if from your Perl program you call another program through system, qx``, or the piped form of open, then that program will inherit any environment variables that your program has set using %ENV. But any program not launched in that way will not be able to see them without substantial additional work. Also, the follwing code:

open my $fh, "| someotherprog.pl" or die $!; $ENV{FOO} = 'bar';
will not cause someotherprog.pl to see the change to the environment variable FOO.

Win32 has a separate notion of "persistent" environment variables stored in the registry. I am not sure how to manipulate them with Perl, but I am fairly certain that modifying %ENV alone will not do it.


In reply to Re: create environment variable at run time by Errto
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.