storableedit.pl is a simple command line editor for Perl Storable files with a shell-like interface. It allows to browse through the data structure, to edit it and even to import/export from/to other storable files.
A complete documentation can be found in storableedit-1.5.html.
Download
You'll find this script on the CPAN script archive as well.
Tutorial
For native Perl speakers, the program is fairly easy to use since it uses Perl syntax to edit the data structure. For sysadmins that just want to change a couple of values in a storable file, here is a short tutorial.
Run the program with your file to edit, e.g.
storableedit.pl mystorablefile
This opens "mystorable" and displays the first level of the data structure. If your file is a contains the configuration of a database replication script, it might look like:
method => synchronize interval => 60 database_from => HASH(0x82bffac) database_to => HASH(0x82be9f8) tables => ARRAY(0x82c0024)
The key "method" has the string value "synchronize" associated with it. If you want to set it to update, type
/ (HASH)> $cur->{'method'} = 'update'
This is a line of Perl code which sets a value in a hash structure. A hash is like a dictionary that contains values ("update") associated with keys ("method"). Note that keys and values are case-sensitive. Similarly, you can change the interval value:
/ (HASH)> $cur->{'interval'} = 120
And since it is evaluated as a Perl expression, the following would also do the job:
/ (HASH)> $cur->{'interval'} = log(10000)/log(10)*30
Or even:
/ (HASH)> $cur->{'interval'} = $cur->{'interval'} * 2
The keys "database_from" and "database_to" are hash structures that are attached to the current hash structure. To edit the destination database, let us dive into "database_to":
/ (HASH)> cd database_to /database_to (HASH)> ls
The prompt indicates the newly selected branch. The "ls" command lists all values of the current hash. You may see
host => databaseserver.mycompany.com database => testdb username => test password => maison2
Note that you see the password in plain text. In fact, storableedit does not know what the values represent and therefore shows all of them in clear. Again, you can easily change the values:
/database_to (HASH)> $cur->{'password'} = 'm@1s0n2'
To verify if the new value was set correctly, type "ls" again.
Let us go back to the root now by typing
/database_to (HASH)> ..
There was an array attached to the "tables" key. This is a simple list of values or structures. To dive into it and show all entries, type
/ (HASH)> cd tables /tables (HASH)> ls
You may see
0 => customers 1 => products 2 => orders 3 => projects
You can change individual values by typing
/tables (HASH)> $cur->[1] = 'productlist'
To remove a value from the end of a list, type
/tables (HASH)> pop @$cur
To append a value at the end of the list
/tables (HASH)> push @$cur, 'employees'
Similarly, the functions "shift" and "unshift" remove resp. add a value at the beginning of the list. To remove a value in the middle of the list, you may use
/tables (HASH)> splice @$cur, 2, 1
This removes 1 element at position 2 (here "orders"). To count the number of elements, type
/tables (HASH)> print scalar @$cur
This just prints the number of elements but does not change anything in your data structure.
After you have accomplished your changes, you can save and close the file by typing
/tables (HASH)> x
This is allowed at any time and in any branch of the structure. In case you want to quit without saving, type
/tables (HASH)> q!
That's it! For a complete list of possibilities and commands please refer to the storableedit documentation.