First of all... is there any reason this should be calling a second program, as opposed to a subroutine? If not, see the first comment in this thread.

If this actually does have to be done via some sort of interprocess communication, the easiest way is to serialize the input hash for the command line, and to serialize the output hash to STDOUT. It looks something like this... starting with the calling script:

my %input_hash = ( ... ); # serialize your hash my $arguments = Dumper \%input_hash; # this is how to escape an arbitrary string for the unix shell $arguments =~ s/'/'\\''/g; $arguments = "'$arguments'"; my $resultstring = `perl my_other_script.pl $arguments`; my %result_hash = %{eval $resultstring};
and the called script would do this:
use Data::Dumper my %input_hash = %{eval $ARGV[0]}; # do stuff... don't print anything! print Dumper \%result_hash; exit;
Of course, this is dependant on being run on unix for the shell-escaping. If this were being run on a different system, you would need to escape the command-line appropriately. If you wanted this to be truly cross-platform, though, you'd have to pipe in the input string, which would require you to use IPC::open2 (allows you to create both a pipe in and a pipe out of a process... backticks are only a pipe out, but are simpler to use).

------------
:Wq
Not an editor command: Wq

In reply to Re: Calls to other Perl programs by etcshadow
in thread Calls to other Perl programs by mcogan1966

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.