File::Inplace(3pm)
π File::Inplace π
ok bestie, so this whole page is the manual for File::Inplace(3pm) β that's the User Contributed Perl Documentation section, iykyk β and it's literally about editing files in place. Let's get into it π
β¨ NAME β¨
File::Inplace β Perl module for in-place editing of files
πΈ SYNOPSIS πΈ
use File::Inplace;
my $editor = new File::Inplace(file => "file.txt");
while (my ($line) = $editor->next_line) {
$editor->replace_line(reverse $line);
}
$editor->commit;
π DESCRIPTION π
So File::Inplace is a perl module that exists to make the super common task of editing a file in-place way less of a whole thing. It was inspired by the various flavors of perl's -i option, but it's built for editing that's a little more structured and reusable than what command-line perl usually lets you get away with. Periodt.
The big promise here β and it's giving main character energy ngl β is file integrity. Meaning: either all the changes you made get saved to the file, or none of them do. No half-edited mess left behind π
It also hands you a bunch of extra goodies: backup creation, automatic field splitting per-line, automatic chomping/unchomping, and the ability to abort your edits partway through without ever touching the original file. Obsessed.
π CONSTRUCTOR π
File::Inplace gives you exactly one constructor, it takes a bunch of parameters, and one of them is required. That's it, that's the whole vibe.
File::Inplace->new(file => "filename", ...)
fileβ the one required parameter, no exceptions bestie. This is the name of the file you're editing. You literally cannot skip this one.suffixβ the suffix for your backup files. If you don't specify it, no backups get made at all. Your call π«Άchompβ if you set this to zero, then automatic chomping justβ¦ doesn't happen. Newlines (or more precisely, whatever's in$/) stay sitting in the strings that come back fromnext_line. And also, the contents of$/won't get appended when you replace lines.regexβ if you specify this, then every line gets split by this parameter whenever you use thenext_line_splitmethod. If you leave it unspecified, it defaults to\s+.separatorβ the default character used to join each line whenreplace_lineis invoked with a list instead of a single value. Defaults to a single space.
π¦ INSTANCE METHODS π¦
$editor->next_line ()β in scalar context, it returns the next line of the input file, orundefif there's no line left. In an array context, it returns a single value of the line, or an empty list if there's no line.$editor->replace_line (value)β replaces the current line in the output file with the value you gave it. If you pass it a list, then each value gets joined by theseparatoryou specified at construction time.$editor->next_line_split ()β literallynext_line, except it splits based on theregexyou specified in the constructor.$editor->has_lines ()β returns true if the file still has any further lines. Vibe check on whether there's more to read.$editor->all_lines ()β returns an array of all the lines in the file being edited. The whole thing, yes ma'am.$editor->replace_all_lines (@lines)β replaces all remaining lines in the file with the@linesyou passed in.$editor->commit ()β completes the edit operation and saves your changes to the edited file. This is the slay moment β¨$editor->rollback ()β aborts the edit process. Nope, we're not doing this anymore.$editor->commit_to_backup ()β saves your edits to the backup file instead of the original file. Sneaky, but legal π
π AUTHOR π
Chip Turner, <chipt@cpan.org>
π COPYRIGHT AND LICENSE π
Copyright (C) 2005 by Chip Turner
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.6.0 or, at your option, any later version of Perl 5 you may have available.
and that's the whole page bestie, no cap π§
ok so real talk, that footer at the bottom of the original said perl v5.38.2 and it was dated 2024-03-04 β so that's the version of perl this page shipped with and the day it got stamped. bye, love u, go edit some files ππΈπ
π¦ where this page comes from
- debian trixie: libfile-inplace-perl 0.20-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libfile-inplace-perl 0.20-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libfile-inplace-perl 0.20-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libfile-inplace-perl 0.20-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms