Logo

Programming-Idioms

History of Idiom 219 > diff from v11 to v12

Edit summary for version 12 by Corion:
New Perl implementation by user [Corion]

Version 11

2020-04-27, 00:05:41

Version 12

2020-04-29, 09:20:33

Idiom #219 Replace multiple spaces with single space

Create string t from the value of string s with each sequence of spaces replaced by a single space.

Explain if only the space characters will be replaced, or the other whitespaces as well: tabs, newlines.

Idiom #219 Replace multiple spaces with single space

Create string t from the value of string s with each sequence of spaces replaced by a single space.

Explain if only the space characters will be replaced, or the other whitespaces as well: tabs, newlines.

Extra Keywords
collapse repeated
Extra Keywords
collapse repeated
Code
my $t = $s;
$s =~ s/ +/ /; # replace only space

# $s =~ s/\s+/ /; # replace all whitespace
Doc URL
https://perldoc.perl.org/perlre.html