This code is broken in a couple of ways. First, I understand you are trying to source the file (with the shell builtin ".") in order to set the environment. You are, for some unknown reason, trying to do that by running $instances[$selection] and telling it that it's name is $conn. (At least I suspect so given the lack of a comma between your arguments to exec.)

That won't work.

Even if it did, it would fail to work in the way you want. The exec would replace the perl process with a shell that runs that source command. In that shell, the environment would be like you want. But that shell would be a child of the invoking shell and although children can inherit an environment from their parent (if the parent exports) it doesn't work the other way around.

You'd need perl to exec a new login shell and specify an initialization file for it. That would get you closer to what you want but the shell that invoked perl in the first place would still be there underneath everything. So, your users would have to exit both shells. That is unless you ran this script as the login shell.

Good luck!

-sauoq
"My two cents aren't worth a dime.";

In reply to Re: Unexpected die by sauoq
in thread Unexpected die by peschkaj

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.