iridescent
iridescent

Reputation: 305

Substituting an element with whitespace. ( Perl Regex )

I am trying to substitute any \n\ character with whitespace, but somehow \s isn't recognised as a whitespace substitution character.

$match_to_array =~ s/\n/\s/;

Upvotes: 0

Views: 114

Answers (1)

Andomar
Andomar

Reputation: 238186

\s is a whole class of characters. It can mean , \t, \r, \n, or \f. You have to tell Perl which one to use. For example, space:

$match_to_array =~ s/\n/ /
                       ^^^

Or tab:

$match_to_array =~ s/\n/\t/
                       ^^^^

Upvotes: 3

Related Questions