Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Re: Replacing multiple spaces into one character?

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


in reply to Re: Replacing multiple spaces into one character?
in thread Replacing multiple spaces into one character?

you could also use the magical ' ' (single space) arg to split, which will remove leading spaces as well...
#!/usr/bin/perl -wT use strict; my $str =' Perlmonks is a very cool place '; $str = join '_', split ' ', $str; print $str, "\n"; =OUTPUT Perlmonks_is_a_very_cool_place

-Blake

Replies are listed 'Best First'.
Re: Re: Re: Replacing multiple spaces into one character?
by tachyon (Chancellor) on Oct 09, 2001 at 07:47 UTC

    Thanks blakem that null string that you get using /\s+/is a pain. I never realised that ' ' was magical.

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      Yeah, its a little screwy. ' ' is magical, but / / is not. I admit to checking the docs on occasion to remember which one is which.

      -Blake