This sounds like data sharing, for which I'd use JSON (it's cross-language).

I've included an example script that shows you how you write JSON to a file called write.pl.

I then show the resulting JSON data in the file, then a script fetch_hash.pl that reads in the data using a command line argument.

write.pl

use warnings; use strict; use JSON; my %first_hash = (fruit => 'banana', Vegetable => 'tomato'); my %second_hash = (work => 'office', family => 'home'); my %hashes = ( first_hash => \%first_hash, second_hash => \%second_hash, ); my $json = encode_json \%hashes; open my $fh, '>', 'data.json' or die $!; print $fh $json;

data.json (JSON file)

{"second_hash":{"work":"office","family":"home"},"first_hash":{"Vegeta +ble":"tomato","fruit":"banana"}}

fetch_hash.pl

use warnings; use strict; use Data::Dumper; use JSON; if (! @ARGV && ($ARGV[0] ne 'first_hash' || $ARGV[0] ne 'second_hash') +){ print "need first_hash or second_hash as arg\n"; exit; } my $want = $ARGV[0]; my $file = 'data.json'; my $json; { local $/; open my $fh, '<', $file or die $!; $json = <$fh>; close $fh; } my $data = decode_json $json; print Dumper $data->{$want};

Output:

$ perl fetch_hash.pl first_hash $VAR1 = { 'fruit' => 'banana', 'Vegetable' => 'tomato' }; $ perl fetch_hash.pl second_hash $VAR1 = { 'work' => 'office', 'family' => 'home' };

In reply to Re: Working with Hashes (stored in other files) by stevieb
in thread Working with Hashes by LovePerling

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.