1String::Trim(3) User Contributed Perl Documentation String::Trim(3)
2
3
4
6 String::Trim - trim whitespace from your strings
7
9 version 0.005
10
12 use String::Trim;
13
14 print "Do it? ";
15 trim(my $response = <>);
16 print "'$response'\n";
17
19 "String::Trim" trims whitespace off your strings. chomp trims only $/
20 (typically, that's newline), but "trim" will trim all leading and
21 trailing whitespace.
22
24 trim
25 Returns the string with all leading and trailing whitespace removed.
26 Trimming undef gives you undef. Alternatively, you can trim in-place.
27
28 my $var = ' my string ';
29 my $trimmed = trim($var);
30 # OR
31 trim($var);
32
33 "trim" also knows how to trim an array or arrayref:
34
35 my @to_trim = (' one ', ' two ', ' three ');
36 my @trimmed = trim(@to_trim);
37 # OR
38 trim(@to_trim);
39 # OR
40 my $trimmed = trim(\@to_trim);
41 # OR
42 trim(\@to_trim);
43
45 "trim" is often used by beginners, who may not understand how to spin
46 their own. While String::Util does have a "trim" function, it depends
47 on Debug::ShowStuff, which depends on Taint, which fails the test
48 suite, and doesn't appear to be maintained. This module installs, is
49 actively maintained, and has no non-core dependencies.
50
51 Other options include Text::Trim and String::Strip (which is
52 implemented in XS, and is therefore likely to be very fast, but
53 requires a C compiler).
54
56 The latest version of this module is available from the Comprehensive
57 Perl Archive Network (CPAN). Visit <http://www.perl.com/CPAN/> to find
58 a CPAN site near you, or see
59 <http://search.cpan.org/dist/String-Trim/>.
60
61 The development version lives at
62 <http://github.com/doherty/String-Trim> and may be cloned from
63 <git://github.com/doherty/String-Trim.git>. Instead of sending
64 patches, please fork this project using the standard git and github
65 infrastructure.
66
68 The development version is on github at
69 <http://github.com/doherty/String-Trim> and may be cloned from
70 <git://github.com/doherty/String-Trim.git>
71
73 No bugs have been reported.
74
75 Please report any bugs or feature requests through the web interface at
76 <https://github.com/doherty/String-Trim/issues>.
77
79 This module was inspired by code at
80 <http://www.perlmonks.org/?node_id=36684> written by japhy (Jeff
81 Pinyan), dragonchild, and Aristotle. This Perl module was written by
82 Mike Doherty.
83
85 • Mike Doherty <doherty@cpan.org>
86
87 • Jeff Pinyan <pinyan@cpan.org>
88
89 • Rob Kinyon <rkinyon@cpan.org>
90
91 • Αριστοτέλης Παγκαλτζής (Aristotle Pagaltzis) <aristotle@cpan.org>
92
94 This software is copyright (c) 2010 by Mike Doherty.
95
96 This is free software; you can redistribute it and/or modify it under
97 the same terms as the Perl 5 programming language system itself.
98
99
100
101perl v5.38.0 2023-07-21 String::Trim(3)