Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Replacing multiple spaces into one character?

by John M. Dlugosz (Monsignor)
on Oct 09, 2001 at 07:10 UTC ( [id://117626]=note: print w/replies, xml ) Need Help??


in reply to Replacing multiple spaces into one character?

Er, it works for me. To wit:
$str= " perlmonks is the coolest"; $str =~ s/\s+/_/g; print $str;
prints: _perlmonks_is_the_coolest

(I left out the i modifier because space is the same in capital or lower-case. I don't think that would change the behavior, though!)

—John

Replies are listed 'Best First'.
Re: Re: Replacing multiple spaces into one character?
by Boldra (Deacon) on Oct 09, 2001 at 18:26 UTC
    Agreed, it works exactly as r.joseph presented it. However you may want to think about using
    $str =~ s/ +/_/g;
    instead, since it doesn't mess with your newline characters. That is, with your version "perl\n" becomes "perl_".

    - Boldra

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://117626]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-25 12:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found