Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Replacing multiple spaces into one character?

by Zaxo (Archbishop)
on Oct 09, 2001 at 07:36 UTC ( [id://117636] : note . print w/replies, xml ) Need Help??


in reply to Replacing multiple spaces into one character?

This uses the magical whitespace arg to split:

my $str = " Perlmonks is the\tcoolest\n \tplace"; $str = join "_", split " ", $str; print $str,$/;
The magic strips leading whitespace and is greedy about the rest. This is a little broader than you asked for, but still does what you want.

After Compline,
Zaxo