The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

File::Edit - A naive, probably buggy, file editor.

SYNOPSIS

    use File::Edit;

    # Replace string in file
    File::Edit->new('build.gradle')
              ->replace('minSdkVersion 16', 'minSdkVersion 21')
              ->save()
              ;

    # Edit text, save to file
    File::Edit->new()
              ->text("  minSdkVersion 16\n  targetSdkVersion 29")
              ->replace('minSdkVersion 16', 'minSdkVersion 21')
              ->save('build.gradle')
              ;

    # Swap lines, save to file
    File::Edit->new()
              ->text("  Do this first\n  Now do that\n  Don't do this")
              ->swap('Do this', 'do that')
              ->save('todo.txt')
              ;

    # Insert at line index, save to file
    File::Edit->new()
              ->text("  Line index 0\n  Line index 1\n  Line index 2")
              ->at(1)->insert('  Inserted line\n')
              ->save('todo.txt')
              ;

METHODS

new

    my $fe = File::Edit->new("some_file.txt");

    Reads in a file for editing.

text

    my $fe = File::Edit->new()->text(some_text);

    Reads in some text for editing.

replace

    $fe->replace($old, $new);

    Replace the $old portion of a single line with $new.

save

    my $fe = File::Edit->new("some_file.txt");
    $fe->save();                # Saves to "some_file.txt"
    $fe->save("other.txt")      # Saves to "other.txt"

swap( $text_1, $text_2 )

The swap($s1, $s2) method finds the line containing string $s1 and finds the line containg string $s2 and swaps both lines.

at( $idx )

The at($idx) sets the index for which actions such as insert($line) will take place.

insert( $line )

The insert( $line ) method inserts the $line at the index location specified. The index location is typically by an earlier call to at($idx). For example:

    $self->at(0)->insert('Start of file')

AUTHOR

Hoe Kit CHEW, <hoekit at gmail.com>

BUGS

Please report any bugs or feature requests to bug-file-edit at rt.cpan.org, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=File-Edit. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc File::Edit

You can also look for information at:

LICENSE AND COPYRIGHT

This software is Copyright (c) 2021 by Hoe Kit CHEW.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)