Okay; setting %ENV is rather simple.
To make it simple, i wrapped part of perls variable types and their functionality in a C++ Class.
template <class T> class Var { typedef Var<T> Base; public: bool ValidPtr() { return m_var != NULL; } virtual Release() { m_var = NULL; } void Attach(T *var) { Release(); m_var = var; } T *Detach() { T *retval = m_var; m_var = NULL; return retval; } virtual void Clear() = 0; virtual void Undef() = 0; operator T *() { return m_var; } operator T *() const { return m_var; } operator const T *() { return m_var; } operator const T *() const { return m_var; } protected: Var(T *var) : m_var(var) { } protected: T* m_var; }; class Scalar : public Var<SV> { public: Scalar(); Scalar(IV iv); Scalar(UV uv); Scalar(double dv); Scalar(const char *str, STRLEN len); Scalar(const std::string & str); Scalar(SV *sv); Scalar(const Scalar & scalar); ~Scalar(); public: void Clear(); void Undef(); }; class Hash : public Var<HV> { public: Hash(); ~Hash(); public: void Clear(); void Undef(); public: Scalar Store(const std::string & key, const Scalar & scalar); }; void Hash::Store(const std::string & key, const Scalar & scalar) { if(ValidPtr()) { SV **result = hv_store( *this, key.c_str(), key.length(), scalar, 0 ); } }
then i wrote a function as part of my interpreter class that returns a hash object
Hash Interpreter::GetHash(const char *name, bool create /*=false*/) { Hash hash; hash.Attach(get_hv(name, create)); return hash; }
And now i'm able to do the follwing fun stuff:
Perl::Hash perlenv = m_perl->GetHash("ENV"); if(perlenv.ValidPtr()) { perlenv.Store("foo", Perl::Scalar("bar")); perlenv.Store("bar", Perl::Scalar("foo")); }
Fun, isn't it? :)

In reply to Re: Perl Embedded: Setting %ENV, STDIN and Workingdirectory by esskar
in thread Perl Embedded: Setting %ENV, STDIN and Workingdirectory by esskar

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.