Logo

Programming-Idioms

History of Idiom 219 > diff from v14 to v15

Edit summary for version 15 by programming-idioms.org:
[Perl] 2 ways => 2 impls, see new impl 3975

Version 14

2020-05-03, 19:28:06

Version 15

2020-05-03, 19:29:02

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
Code
my $t = $s;
$s =~ s/ +/ /;
Comments bubble
Replace only space
Doc URL
https://perldoc.perl.org/perlre.html
Doc URL
https://perldoc.perl.org/perlre.html