1No::Worries::String(3)User Contributed Perl DocumentationNo::Worries::String(3)
2
3
4
6 No::Worries::String - string handling without worries
7
9 use No::Worries::String qw(*);
10
11 # format a number of bytes
12 printf("%s has %s\n", $path, string_bytefmt(-s $path));
13
14 # escape a string
15 printf("found %s\n", string_escape($data));
16
17 # produce a nice output (e.g "1 file" or "3 files")
18 printf("found %s\n", string_quantify($count, "file"));
19
20 # format a table
21 print(string_table([
22 [1, 1, 1],
23 [2, 4, 8],
24 [3, 9, 27],
25 ], header => [qw(x x^2 x^3)]));
26
27 # trim a string
28 $string = string_trim($input);
29
31 This module eases string handling by providing convenient string
32 manipulation functions.
33
35 This module provides the following functions (none of them being
36 exported by default):
37
38 string_bytefmt(NUMBER[, PRECISION])
39 return the given NUMBER formatted as a number of bytes with a
40 suffix such as "kB" or "GB"; the default precision (i.e. number of
41 digits after the decimal dot) is 2
42
43 string_escape(STRING)
44 return a new string with all potentially non-printable characters
45 escaped; this includes ASCII control characters, non-7bit ASCII and
46 Unicode characters
47
48 string_plural(STRING)
49 assuming that STRING is an English noun, returns its plural form
50
51 string_quantify(NUMBER, STRING)
52 assuming that STRING is an English noun, returns a string saying
53 how much of it there is; e.g. "string_quantify(2, "foot")" is "2
54 feet"
55
56 string_table(TABLE[, OPTIONS])
57 transform the given table (a reference to an array of arrays of
58 strings) into a formatted multi-line string; supported options:
59
60 · "align": array reference of alignment directions (default:
61 "left"); possible values are "left", "center" and "right"
62
63 · "colsep": column separator string (default: " | ")
64
65 · "header": array reference of column headers (default: none)
66
67 · "headsep": header separator (default: "=")
68
69 · "indent": string to prepend to each line (default: "")
70
71 string_trim(STRING)
72 return a new string with leading and trailing spaces removed
73
75 No::Worries.
76
78 Lionel Cons <http://cern.ch/lionel.cons>
79
80 Copyright (C) CERN 2012-2017
81
82
83
84perl v5.28.0 2017-08-01 No::Worries::String(3)