aks
aks

Reputation: 1359

How can I remove all whitespaces and linebreaks in Perl?

I have a string that looks like this...

"
http://www.example.com/

example.pdf"

I need to remove the whitespaces and linebreaks. How do I do this? My result should be

"http://www.example.com/example.pdf"

Upvotes: 6

Views: 26937

Answers (2)

Eugene Yarmash
Eugene Yarmash

Reputation: 149736

Just use the s/// substitution operator:

$string =~ s/\s+//g;

The \s character class matches a whitespace character, the set [\ \t\r\n\f] and others.

Upvotes: 24

Benoit
Benoit

Reputation: 79165

while (<>) { s/\s+//g; print; }

?

Upvotes: 0

Related Questions