storableedit.pl - Edit Perl Storable Files
storableedit.pl PERL_STORABLE_FILE
storableedit.pl is a simple command line editor for Perl Storable files. Its interface is similar to a shell.
When the program is started, it reads the whole file and displays the first level of the data structure. One can then dive into the structure with the cd command and display values with the ls or l commands.
The data can be modified with usual Perl expressions, where $cur is a reference to the current node $data is a reference to the root node of the data
To save the data back to file and exit, type x or exit. To exit without saving, type q or quit. If you have modified the data, you can force discarding the changes with q! or quit!.
To move up to the parent, type cd .. (or just ..). To move up two steps, type cd ... (or just ...).
Note that ls doesn't take any arguments, i.e. you can't use regexes to display only parts of the content.
If a command is not recognized as a built-in command, the whole line is passed to the Perl eval()
function. Two variables are provided to access the data structure:
$cur is a reference to the current node
$data is a reference to the root node of the data
Note that this script does not check what you are doing. It does NOT ask to confirm when you delete values. But keep in mind that you can always quit with q! to discard all changes.
In case of syntax or runtime errors, the Perl error messages are shown.
Simple examples:
$cur->{'foo'} = 'bar'; # if $cur is a hashref $cur->[0] = 'bar'; # if $cur is an arrayref $cur->[1] = {'a' => 'b'}; # creates new hashref $cur->[2] = ['a', 'b']; # creates new arrayref
Fancy examples:
push @$cur, 'bar'; # adds a new value to the current arrayref
push @$data, pop @$cur; # more array ops
$cur->{'list'} = split(/,/, $cur->{'string'}; # splitting a string
$cur->{'list'} = [sort values %{$cur->{'hashref'}}]; # sorted values of a hashref
print join("\n", grep {/abc/} keys %$cur) # grep, join ... it's Perl!
$data = $cur; # sets the current node as new root # note that you might loose data ...
$cur->{'imported'}=retrieve('otherfile.store'); # imports from another Storable file
store($cur, 'otherfile.store'); # exports to another Storable file
Perl-OO examples:
use My::Module; # load My::Module
$cur->{'obj'} = My::Module->new(); # create a new My::Module object
$cur->{'obj'}->my_method(); # call a method
bless $cur, 'My::Module'; # blessing manually
To enter multiline Perl expressions, put a backslash (\) at the end of each line. Example:
open(my $fh, '<', 'myfile.txt');\ $cur->{'firstline'}=<$fh>;\ close $fh;
Thomas Lochmatter <thl@lothosoft.ch>.
A simple command line editor for Perl Storable files. The interface is similar to a shell. It allows to easily walk through the data structure of the file and to list and change values.