tags:

views:

76

answers:

2

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"

+5  A: 
$string =~ s/\s+//g;

From perldoc perlretut:

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

eugene y
@eugene - you want to replace the whitespace characters with `s/...`. Corrected for you.
eumiro
I'm getting an error `Useless use of division (/) in void context` and `Bareword "g" not allowed`
Rajesh
never mind..it worked
Rajesh
@eumiro: thanks. I was editing the post at the same time :)
eugene y
A: 

Hello, what about:

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

?

Benoit
You can drop the `chomp;`.
codaddict