How to reverse a HASH into string format?

How to reverse a HASH into string format?

am 26.07.2005 07:53:44 von ^_____^

I have defined a HASH like following:

my %data = ("name" => "Paul",
"age" => "100",
"address" => {
"street" => "1234 test st.",
"city" => "my town",
"zip" => "12345"
});


But now I am trying to dump this hash into another file, and I want it to be
in the same format since it will be used by another script later on. Is
there a build-in functions I could use in perl?

Thank you

Re: How to reverse a HASH into string format?

am 26.07.2005 11:05:46 von mlj

^___^ wrote:
> I have defined a HASH like following:
>
> my %data = ("name" => "Paul",
> "age" => "100",
> "address" => {
> "street" => "1234 test st.",
> "city" => "my town",
> "zip" => "12345"
> });
>
>
> But now I am trying to dump this hash into another file, and I want it to be
> in the same format since it will be used by another script later on. Is
> there a build-in functions I could use in perl?

From perlfaq4:

# To store the data:
use Storable;
store(\%data, "filename");

# To retrieve the data:
use Storable;
my %data = %{ retrieve("filename") };

Re: How to reverse a HASH into string format?

am 26.07.2005 14:40:04 von Paul Lalli

^___^ wrote:
> I have defined a HASH like following:
>
> my %data = ("name" => "Paul",
> "age" => "100",
> "address" => {
> "street" => "1234 test st.",
> "city" => "my town",
> "zip" => "12345"
> });
>
>
> But now I am trying to dump this hash into another file, and I want it to be
> in the same format since it will be used by another script later on. Is
> there a build-in functions I could use in perl?

In addition to mlj's Storable suggestion, have you considered going all
the way and putting this shared variable in a module? That way you
need only define the hash once, and any script that uses the module
will have access to it.

See also:
perldoc perlmod
perldoc Exporter

Paul Lalli