Text-Lossy
view release on metacpan or search on metacpan
lib/Text/Lossy.pm view on Meta::CPAN
alone. Other whitespace at the end will get collapsed into a single newline.
If the text ends in whitespace that does not contain a new line, it is replaced
by a space, as before.
This filter is most useful if you are creating a Unix-style text filter, and do not
want to buffer the entire input before writing the (only) line to C<stdout>. The
newline at the end will allow downstream processes to work on new lines, too.
Otherwise, this filter is not quite as efficient as the L<whitespace> filter.
Any newlines in the middle of text are collapsed to a space, too. This is especially
useful if you are reading in "paragraph mode", e.g. C<$/ = ''>, as you will get
one long line per former paragraph.
=cut
sub whitespace_nl {
my ($text) = @_;
# Remember whether a newline was present
my $has_nl = ($text =~ m{ \n \s* \z }xms) ? 1 : 0;
$text =~ s{ \s+ }{ }xmsg;
$text =~ s{ \A \s+ }{}xms;
script/text-lossy view on Meta::CPAN
my $available_filters = undef;
my @filters = ();
GetOptions(
'help' => \$help,
'version' => \$version,
'filter=s' => \@filters,
'1' => sub { @filters = qw( lower ); },
'2' => sub { @filters = qw( lower whitespace ); },
'3' => sub { @filters = qw( lower punctuation_sp whitespace ); },
'paragraph' => sub { $/ = ''; }, # global, we're in top scope here
'2l' => sub { @filters = qw( lower whitespace_nl ); },
'3l' => sub { @filters = qw( lower punctuation_sp whitespace_nl ); },
'available-filters' => \$available_filters,
) or pod2usage(2);
if ($help) {
pod2usage(1)
}
if ($version) {
print "text-lossy version $Text::Lossy::VERSION\n";
exit(0);
( run in 0.263 second using v1.01-cache-2.11-cpan-49f99fa48dc )