passing a hash to another script in perl

I have a script (say script1.sh ) and I am calling a script (say script2.sh) within the script1.sh. Here in script1.sh I have a hash ( say %hash1) and i have to pass this hash to script2.sh. Basically i have to do some processing in Scirpt2.sh based on the hash(key,values). I wanted to know how can I achieve this?. Can we pass hash or use some global kind of vairable where hash in script1.sh can be referenced in script2.sh ?

Ideas are appreciated and thanks in advance
Ammu

It looks like you are calling various Perl scripts from from within shell. Basically, each Perl process has its own range of memory, and one process cannot access another processes memory structures (for obvious reasons) without using some form of IPC or persistence.

I would recommend in your case to use serialization and store the data in a file so the other process can easily access it. A quick search came across this:

Perl 5.8 Documentation - Storable - persistence for Perl data structures

First I'd like to remind you if possible to use some other alternative methods to achieve your goal (eg. combining the 2 scripts into one), as it seems the method you mentioned is a little complicated.

But if you persist, read the followings. Basically, you need some kinds of IPC (inter process communication) methods to transfer the hash data. there are a lot of options. steps, 1. create pipes in the script1.sh before calling script2.sh. 2. calling script2.sh 3. script1.sh write the hash data to the pipe, you can use whatever for format you like, I recommend using Data::Dumper(). 4. script2.sh reads the data coming from script1.sh, via the pipe 5. convert the data you received to the object in perl. This is simple if using Data::Dumper(), just eval ().