[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]

:=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";

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 &lt;*&gt; docx at io.com &lt;*&gt; <a  rel="nofollow" href="http://www.io.com/~docx/";>http://www.io.com/~docx/</a>
&quot;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.&quot; -- Cowboy Mouth, 'Easy'

<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>
<li>Prev by Date:
<strong><a href="msg00632.html">[ale] Perl quickie</a></strong>
<li>Next by Date:
<strong><a href="msg00634.html">[ale] Perl quickie</a></strong>
<li>Previous by thread:
<strong><a href="msg00630.html">[ale] Perl quickie</a></strong>
<li>Next by thread:
<strong><a href="msg00668.html">[ale] Perl quickie</a></strong>
<li><a href="maillist.html#00633"><strong>Date</strong></a></li>
<li><a href="threads.html#00633"><strong>Thread</strong></a></li>