1File::Inplace(3)      User Contributed Perl Documentation     File::Inplace(3)
2
3
4

NAME

6       File::Inplace - Perl module for in-place editing of files
7

SYNOPSIS

9         use File::Inplace;
10
11         my $editor = new File::Inplace(file => "file.txt");
12         while (my ($line) = $editor->next_line) {
13           $editor->replace_line(reverse $line);
14         }
15         $editor->commit;
16

DESCRIPTION

18       File::Inplace is a perl module intended to ease the common task of
19       editing a file in-place.  Inspired by variations of perl's -i option,
20       this module is intended for somewhat more structured and reusable
21       editing than command line perl typically allows.  File::Inplace
22       endeavors to guarantee file integrity; that is, either all of the
23       changes made will be saved to the file, or none will.  It also offers
24       functionality such as backup creation, automatic field splitting per-
25       line, automatic chomping/unchomping, and aborting edits partially
26       through without affecting the original file.
27

CONSTRUCTOR

29       File::Inplace offers one constructor that accepts a number of
30       parameters, one of which is required.
31
32       File::Inplace->new(file => "filename", ...)
33           file
34               The one required parameter.  This is the name of the file to
35               edit.
36
37           suffix
38               The suffix for backup files.  If not specified, no backups are
39               made.
40
41           chomp
42               If set to zero, then automatic chomping will not be performed.
43               Newlines (actually, the contents of $/) will remain in strings
44               returned from "next_line".  Additionally, the contents of $/
45               will not be appended when replacing lines.
46
47           regex
48               If specified, then each line will be split by this parameter
49               when using "next_line_split" method.  If unspecified, then this
50               defaults to \s+.
51
52           separator
53               The default character used to join each line when replace_line
54               is invoked with a list instead of a single value.  Defaults to
55               a single space.
56

INSTANCE METHODS

58       $editor->next_line ()
59           In scalar context, it returns the next line of the input file, or
60           undef if there is no line.  In an array context, it returns a
61           single value of the line, or an empty list if there is no line.
62
63       $editor->replace_line (value)
64           Replaces the current line in the output file with the specified
65           value.  If passed a list, then each valie is joined by the
66           "separator" specified at construction time.
67
68       $editor->next_line_split ()
69           Line "next_line", except splits based on the "regex" specified in
70           the constructor.
71
72       $editor->has_lines ()
73           Returns true if the file contains any further lines.
74
75       $editor->all_lines ()
76           Returns an array of all lines in the file being edited.
77
78       $editor->replace_all_lines (@lines)
79           Replaces all remaining lines in the file with the specified @lines.
80
81       $editor->commit ()
82           Completes the edit operation and saves the changes to the edited
83           file.
84
85       $editor->rollback ()
86           Aborts the edit process.
87
88       $editor->commit_to_backup ()
89           Saves edits to the backup file instead of the original file.
90

AUTHOR

92       Chip Turner, <chipt@cpan.org>
93
95       Copyright (C) 2005 by Chip Turner
96
97       This library is free software; you can redistribute it and/or modify it
98       under the same terms as Perl itself, either Perl version 5.6.0 or, at
99       your option, any later version of Perl 5 you may have available.
100

POD ERRORS

102       Hey! The above document had some coding errors, which are explained
103       below:
104
105       Around line 283:
106           You forgot a '=back' before '=head1'
107
108       Around line 285:
109           '=item' outside of any '=over'
110
111
112
113perl v5.30.0                      2019-07-26                  File::Inplace(3)
Impressum