[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
- <!--x-content-type: text/plain -->
- <!--x-date: Fri Jan 16 11:32:49 2004 -->
- <!--x-from-r13: qbpk ng vb.pbz (Rlyna @beguehc) -->
- <!--x-message-id: Pine.LNX.4.44.0401161018180.13594-[email protected] -->
- <!--x-reference: 1074269863.6441.11.camel@devel --> "http://www.w3.org/TR/html4/loose.dtd">
- <!--x-subject: [ale] Perl quickie -->
- <li><em>date</em>: Fri Jan 16 11:32:49 2004</li>
- <li><em>from</em>: docx at io.com (Dylan Northrup)</li>
- <li><em>in-reply-to</em>: <1074269863.6441.11.camel@devel></li>
- <li><em>subject</em>: [ale] Perl quickie</li>
:=I'm trying to remove all spaces in a string.
:=
:= my $dir = $tag->{GENRE}."/".$info->{ARTIST}."/".$info->{ALBUM};
:= my $dir =~ (s/\ /\_/g);
:= print $dir."\n";
:=
:=What is the right way to do it?
plato> perl
$dir = '/foo/bar baz/quux blah';
$dir =~ s/\s+/_/g;
print $dir . "\n";
^D
/foo/bar_baz/quux_blah
I don't know why you have the parentheses around the substitution. I also
used '\s+' to collapse any instances of multiple spaces to a single '_'.
Another benefit of using '\s' is it will also get tabs, returns, etc. in
addition to plain old spaces.
--
Dylan Northrup <*> docx at io.com <*> <a rel="nofollow" href="http://www.io.com/~docx/">http://www.io.com/~docx/</a>
"Harder to work, harder to strive, hard to be glad to be alive, but it's
really worth it if you give it a try." -- Cowboy Mouth, 'Easy'
</pre>
<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<hr>
<!--X-Follow-Ups-End-->
<!--X-References-->
<ul><li><strong>References</strong>:
<ul>
<li><strong><a name="00630" href="msg00630.html">[ale] Perl quickie</a></strong>
<ul><li><em>From:</em> cfowler at outpostsentinel.com (Chris Fowler)</li></ul></li>
</ul></li></ul>
<!--X-References-End-->
<!--X-BotPNI-->
<ul>
<li>Prev by Date:
<strong><a href="msg00632.html">[ale] Perl quickie</a></strong>
</li>
<li>Next by Date:
<strong><a href="msg00634.html">[ale] Perl quickie</a></strong>
</li>
<li>Previous by thread:
<strong><a href="msg00630.html">[ale] Perl quickie</a></strong>
</li>
<li>Next by thread:
<strong><a href="msg00668.html">[ale] Perl quickie</a></strong>
</li>
<li>Index(es):
<ul>
<li><a href="maillist.html#00633"><strong>Date</strong></a></li>
<li><a href="threads.html#00633"><strong>Thread</strong></a></li>
</ul>
</li>
</ul>
<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
</body>
</html>