G'day Sriram,

The built-in module Storable allows you to store Perl data structures and retrieve them later. This may be suitable for your use.

Here's a very quick-and-dirty example of a "parent script" (pm_1078041_parent.pl) calling a "child script" (pm_1078041_child.pl). The child creates a hashref, stores it and exits. The parent retrieves the hashref and uses it to create XML.

[XML::Simple was only used for demonstration purposes. Please don't take that as any sort of recommendation.]

The parent script (pm_1078041_parent.pl):

#!/usr/bin/env perl use strict; use warnings; use Storable; use XML::Simple; my $file = 'pm_1078041_store'; `pm_1078041_child.pl`; my $hashref = retrieve $file; my $xml = XML::Simple->new->XMLout($hashref); print $xml;

The child script (pm_1078041_child.pl):

#!/usr/bin/env perl use strict; use warnings; use Storable; my $file = 'pm_1078041_store'; my $hashref = { key1 => 'qwerty', key2 => 'asdfgh', key3 => { A => 1, B => 2, C => 3, }, key4 => [5, 6, 7], }; store $hashref => $file;

A sample run:

$ pm_1078041_parent.pl <opt key1="qwerty" key2="asdfgh"> <key3 A="1" B="2" C="3" /> <key4>5</key4> <key4>6</key4> <key4>7</key4> </opt>

-- Ken


In reply to Re: How to return Hashref from one script to another script? by kcott
in thread How to return Hashref from one script to another script? by sriram83.life

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.