To explain, the answers above keep the two "scripts" in the same process, and that is required in order to pass Perl objects. An object variable is only a reference with a little extra data (its class). The reference contains a memory address that only applies to the current process (assuming you are dealing with a virtual memory system like UNIX, Linux, or Windows). Passing an address as an argument would not work because that same memory address could be used for something else, or might be invalid. Might work on Windows 95, but I'm sure you are not that desperate.

You could do it other ways if you really need two processes. The simplest would be to pass the data rather than the reference, using any number of mechanisms, including Data::Dumper. You could also use shared memory (shmem), but that has other issues concerning synchronisation. You could use fork, which creates a process (thread on Windows) as an almost identical copy of the original, right down to the memory addresses. It really depends why you want to do this.

In reply to Re: Pass class object as argument to perl script by cdarke
in thread Pass class object as argument to perl script by gnvivek

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.