NAME

storableedit.pl - Edit Perl Storable Files


SYNOPSIS

storableedit.pl PERL_STORABLE_FILE


DESCRIPTION

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!.


BUILT-IN COMMANDS

cd ELEMENT
Moves into ELEMENT. If the current node is a hashref, ELEMENT must be a key. The new current node will be $cur->{'ELEMENT'}. If the current node is an arrayref, ELEMENT must be an index and $cur->[ELEMENT] becomes the new current node. If the current node is a reference to a reference, type cd ref. Note that you can only move into new references (hashref, arrayref or ref, but not scalars).

To move up to the parent, type cd .. (or just ..). To move up two steps, type cd ... (or just ...).

..
Shortcut for cd ..

...
Shortcut for cd ...

ls
Displays the contents of the current node. For hashrefs, all key/value pairs are listed. For arrayrefs, all elements are listed.

Note that ls doesn't take any arguments, i.e. you can't use regexes to display only parts of the content.

l
Similar as ls, but cuts all values that are longer than 50.

x, exit
Saves the (modified) data structure and quits.

q, quit
Quits without saving. If the data structure has been modified, a warning is shown.

q!, quit!
Forces quiting without saving.


PERL EXPRESSIONS

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;


CAVEATS

Cyclic Structures
storableedit.pl also handles cyclic structures.

File Handles
File handles are not stored by the Storable module (for obvious reasons).

Objects
When loading storable files with (blessed) objects, the corresponding modules are not automatically loaded. If you need to invoke methods, type use My::Module; or require ``/path/to/module.pm''; to load the necessary module(s).


AUTHORS

Thomas Lochmatter <thl@lothosoft.ch>.


README

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.