String::Nudge - Indents all lines in a multi-line string
Version 1.0002, released 2021-07-29.
use String::Nudge; sub out { print nudge q{ A long text. }; } # is exactly the same as sub out { print q{ A long text. }; }
String::Nudge provides nudge, a simple function that indents all lines in a multi line string.
nudge
# ' hello' my $string = nudge 'hello';
# ' hello' my $string = nudge 8, 'hello';
If $number_of_spaces is not given (or isn't an integer >= 0) its default value is 4.
$number_of_spaces
4
Every line in $string is indented by $number_of_spaces. Lines only consisting of white space is trimmed (but not removed).
$string
Syntax::Feature::Qi adds qi and qqi that removes the same amount of leading whitespace as the first (significant) line has from all lines in a string:
qi
qqi
# these three packages are equivalent: package Example::Nudge { use String::Nudge; use syntax 'qi'; sub out { print nudge qi{ sub funcname { print 'stuff'; } }; } } package Example::Q { sub out { print q{ sub funcname { print 'stuff'; } }; } } package Example::HereDoc { sub out { (my $text = <<" END") =~ s{^ {8}}{}gm; sub funcname { print 'stuff'; } END print $text; } }
Syntax::Feature::Qs adds qs and qqs that removes all leading whitespace from all lines in a string:
qs
qqs
# these three packages are equivalent: package Example::Nudge { use String::Nudge; use syntax 'qs'; sub out { print nudge qs{ This is a multi line string. }; } } package Example::Q { sub out { print q{ This is a multi line string. }; } } package Example::HereDoc { sub out { (my $text = <<" END") =~ s{^ {8}}{}gm; This is a multi line string. END print $text; } }
Indent::String
String::Indent
https://github.com/Csson/p5-String-Nudge
https://metacpan.org/release/String-Nudge
Erik Carlsson <info@code301.com>
This software is copyright (c) 2021 by Erik Carlsson.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install String::Nudge, copy and paste the appropriate command in to your terminal.
cpanm
cpanm String::Nudge
CPAN shell
perl -MCPAN -e shell install String::Nudge
For more information on module installation, please visit the detailed CPAN module installation guide.