GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
String::Pad(3) User Contributed Perl Documentation String::Pad(3)

String::Pad - String padding routines

This document describes version 0.021 of String::Pad (from Perl distribution String-Pad), released on 2021-08-01.

 use String::Pad qw(pad);

 my $res;

 # pad a single string
 $res = pad("foo", 5);           # => "foo  "  # default $which is 'right' or 'r'
 $res = pad("foo", 5, "left");   # => "  foo"  # left padding, which means to be 'right-justified'
 $res = pad("foo", 5, "l");      # => "  foo"  # 'l' is same thing as 'left'
 $res = pad("foo", 5, "c");      # => " foo "  # 'center' ('c') padding
 $res = pad("foo", 5, "c", "x"); # => "xfoox"  # pad with a custom character
 $res = pad("foo", 5, "c", "x"); # => "xfoox"  # pad with a custom character

 $res = pad("foobar", 5, 'r', undef, 'truncate'); # => "fooba"

 # pad multiple strings

Usage:

 $res = pad($text | \@texts, $width [, $which [, $padchar=' ' [, $truncate=0] ] ] ); # => str or arrayref

Return $text padded with $padchar to $width columns. Can accept multiple texts ("\@texts"); in which case will return a new arrayref of padded texts.

$width can be undef or -1 if you supply multiple texts, in which case the width will be determined from the longest text.

$which is either "r" or "right" for padding on the right (the default if not specified), "l" or "left" for padding on the right, or "c" or "center" or "centre" for left+right padding to center the text. Note that "r" will mean "left justified", while "l" will mean "right justified".

$padchar is whitespace if not specified. It should be string having the width of 1 column.

$truncate is boolean. When set to 1, then text will be truncated when it is longer than $width.

Please visit the project's homepage at <https://metacpan.org/release/String-Pad>.

Source repository is at <https://github.com/perlancar/perl-String-Pad>.

Please report any bugs or feature requests on the bugtracker website <https://rt.cpan.org/Public/Dist/Display.html?Name=String-Pad>

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

Other string padding modules: Text::Padding, Text::WideChar::Util (for strings that contain wide Unicode characters), Text::ANSI::Util (for strings that contain ANSI color codes), Text::ANSIWide::Util (for strings that contain both ANSI color codes and wide Unicode characters).

Other alignment modules: Number::Pad (for padding numbers so that the decimal points align).

perlancar <perlancar@cpan.org>

This software is copyright (c) 2021, 2018, 2014 by perlancar@cpan.org.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

2021-08-01 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.