File::Edit - A naive, probably buggy, file editor.
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') ;
my $fe = File::Edit->new("some_file.txt"); Reads in a file for editing.
my $fe = File::Edit->new()->text(some_text); Reads in some text for editing.
$fe->replace($old, $new); Replace the $old portion of a single line with $new.
my $fe = File::Edit->new("some_file.txt"); $fe->save(); # Saves to "some_file.txt" $fe->save("other.txt") # Saves to "other.txt"
The swap($s1, $s2) method finds the line containing string $s1 and finds the line containg string $s2 and swaps both lines.
The at($idx) sets the index for which actions such as insert($line) will take place.
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')
Hoe Kit CHEW, <hoekit at gmail.com>
<hoekit at gmail.com>
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.
bug-file-edit at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc File::Edit
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
https://rt.cpan.org/NoAuth/Bugs.html?Dist=File-Edit
CPAN Ratings
https://cpanratings.perl.org/d/File-Edit
Search CPAN
https://metacpan.org/release/File-Edit
This software is Copyright (c) 2021 by Hoe Kit CHEW.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
To install File::Edit, copy and paste the appropriate command in to your terminal.
cpanm
cpanm File::Edit
CPAN shell
perl -MCPAN -e shell install File::Edit
For more information on module installation, please visit the detailed CPAN module installation guide.