On Jan 25, 2008 4:45 AM, praveen mall <[EMAIL PROTECTED]> wrote:
snip
> There are two script. From first script I need to call the second program
> and in second program I want to receive the hash. I have complete hash in
> first program and calling second program by system call by passing hash
> reference as a parameter.
snip

I believe you are placing constraints on yourself that do not actually
exist, but we will work with them for now.  You need some form of
IPC*.  The easiest to understand is the simple file method: script one
writes a file to disk and script two reads that file.  Now that we
know how to get the two scripts talking, we need to know how to
transfer a hash along that conduit.  We need to serialize it (turn it
into a string that contains all of the information we need).  There
are many functions in Perl that can do this for us and which one is
best depends on the data structure to be serialized and your other
needs.  For now, let's us one that is in Core Perl: Storable**.

Here is the first script
#!/usr/bin/perl

use strict;
use warnings;
use Storable;

my %h = (a => 1, b => 2, c => 3);

store(\%h, "/tmp/perlipc.$$")
    or die "could not store hash in /tmp/perlipc.$$: $!";

system("perl", "second.pl", $$) == 0
    or die "could not run second.pl";

Here is the second script
#!/usr/bin/perl

use strict;
use warnings;
use Storable;
use Data::Dumper;

my $parentpid = shift;
my $href = retrieve("/tmp/perlipc.$parentpid")
    or die "could not retrieve hash from /tmp/perlipc.$parentpid: $!";

print Dumper($href);


* inter process communication
** http://perldoc.perl.org/Storable.html

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to