in reply to Re: Hash File to Binary ?
in thread Hash File to Binary ?

roboticus thanks for explaining. That was helpful.
As you can see from my response below all im trying to do is use the command "store" on hash table that is stored in file.
what is the proper way to do this? Or how can I store my Dumper output in a variable properly.
tried this but didn't work where is my problem ?

#CODE1 $data = $xml->XMLin("output.xml"); my $hash_table = Dumper($data); store \%hash_table, 'binary_hash.txt';
#CODE2 $data = $xml->XMLin("output.xml"); print MYFILE Dumper($data); store MYFILE, 'binary_hash.txt';

Replies are listed 'Best First'.
Re^3: Hash File to Binary ?
by roboticus (Chancellor) on Dec 12, 2013 at 14:58 UTC

    zak_s:

    Dumper only displays the data in readable form. The store function writes it into a file in such a way that retrieve can get it back out. Here's a quick example that stores a data structure to a file:

    #!/usr/bin/perl use strict; use warnings; use Storable; # You'll get it via XMLin, I just hardcoded some data my $data = { foo=>'bar', bim=>'bam' }; store $data, 'MyFile.data';

    Now, when we have another program that wants to use the data, we just retrieve it first:

    #!/usr/bin/perl use strict; use warnings; use Storable; use Data::Dumper; my $ref = retrieve('MyFile.data'); print Dumper($ref);

    We're only using Data::Dumper to display the data, you won't need it in either of your scripts unless you need to print it to the screen for debugging. (Which is what I often do.)

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

      Thanks a lot for all of you. Worked!
      I have no idea what I did wrong last time for this not to work even though I tried it.

Re^3: Hash File to Binary ?
by Anonymous Monk on Dec 12, 2013 at 15:04 UTC
    use XML::Simple; use Storable; $data = XMLin('foo.xml'); store $data, 'foo.dat';