Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I remove all whitespaces and linebreaks in Perl?

Tags:

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"

like image 653
aks Avatar asked Oct 14 '10 08:10

aks


1 Answers

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.

like image 50
Eugene Yarmash Avatar answered Oct 17 '22 20:10

Eugene Yarmash