File: wrap_the_lines_in_a_file.pl

package info (click to toggle)
libfile-util-perl 4.201720-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 840 kB
  • sloc: perl: 4,353; makefile: 2
file content (21 lines) | stat: -rw-r--r-- 509 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# ABSTRACT: open a file, wrap its lines, save the file with the newly formatted content

use strict; # always
use warnings;
use File::Util qw( NL );
use Text::Wrap qw( wrap );

$Text::Wrap::columns = 72; # wrap text at this many columns

my $ftl  = File::Util->new();
my $file = 'example.txt'; # file to wrap and save (must already exist)

$ftl->write_file(
  filename => $file,
  content => wrap('', '', $ftl->load_file( $file ))
);

# display the newly formatted file
print $ftl->load_file( $file );

exit;