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:
and the called script would do this: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};
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).use Data::Dumper my %input_hash = %{eval $ARGV[0]}; # do stuff... don't print anything! print Dumper \%result_hash; exit;
In reply to Re: Calls to other Perl programs
by etcshadow
in thread Calls to other Perl programs
by mcogan1966
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |