I am confused about the storable module in Perl. In the available documentation for it http://perldoc.perl.org/Storable.html, it doesn't describe much about the file that it uses to store the data structure. What kind of extension is the file? When I create a file for the module to use, do I need to assign it an special extension so it knows how to read it or is a simple .txt file something it can use?


Since the docs don't say you have to have any specific extension for your file name, I guess you can have any that you want. Why not try it with a simple example?

I haven't used Storable and am not an expert, but I see that the docs give simple examples storing the contents of hashes. If you run the following:

use strict;
use warnings;

use Data::Dumper;
use Storable;
my %table = (cat => 'animal',
             dog => 'animal',
             carrot => 'vegetable',
             granite => 'mineral');

store \%table, 'avm.txt';
my $hashref = retrieve('avm.txt');

#Dump the contents of the $hashref
print Dumper($hashref);

It works fine, but if you use a text editor to view the 'avm.txt' file you will see that it has a lot of unprintable characters, so adding the '.txt' extension could be kind of misleading.

Storable serialise data to binary, that is, it stores the perl representation of the data-structure/object in a file, referred to as an "image".

That file can only be used by another Perl program that uses Storable to read and use the data. Therefore, there is no need for an extension to tell the OS that it should be opened by any application. Since the file isn't usable outside of a Storable perl program, there's a lack of information about it in the module's documentation.

commented: Good explanation. +2