[libvirt] [PATCH 3/4] virsh.c: remove all "syntax" vshCmdInfo entries.

Daniel P. Berrange berrange at redhat.com
Mon Dec 8 10:57:09 UTC 2008


On Mon, Dec 08, 2008 at 11:35:03AM +0100, Daniel Veillard wrote:
> On Fri, Dec 05, 2008 at 07:25:02PM +0100, Jim Meyering wrote:
> > 
> > * src/virsh.c: ... now that it's generated.
> > ---
> > FYI, I made this change with the following one-liner:
> > 
> >     perl -ni -e '/"syntax",/ or print' src/virsh.c
> 
>   I still don't understand perl (" or print" ???) but patch is trivial,

The '-i' flag tells Perl to iterate over the lines in the input
file one at a time, applying the code listed, and writing output
back to the original file. So basically modifying the file in-place.

The first half of the code does a regular expression match  /"syntax",/
The 'or print' bit means that if the regular expression does not match,
then print out the line being processed. So this code basically keeps
every line except those containing the string "syntax",

A much more verbose way of writing this same thing is

    rename "src/virsh.c", "src/virsh.c.bak"

    open SOURCE, "src/virsh.c.bak";
    open DEST, "src/virsh.c"

    while (my $line = <SOURCE>) {
        if ($line =~ /"syntax",/) {
            # Do nothing, drop this line
        } else {
            print DEST $line;
        }
    }

    close DEST;
    close SOURCE;

    unlink "src/virsh.c.bak"
    
Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|




More information about the libvir-list mailing list