foreach my $tmp_name (`dcop amarok playlist filenames`) {
$tmp_string .= "[$tmp_idx]\t";
# remove common suffixes
chomp $tmp_name;
for my $suffix ( '.mp3', '.flac', '.shn', '.ogg' ) {
$tmp_name =~ s/$suffix$//;
}
# and append the filename
$tmp_string .=
( $playing =~ /$tmp_name/ ) ? "*** $tmp_name ***\n" : "$tmp_
+name\n";
$tmp_idx++;
}
Your algorithm is broken, see for example:
$ perl -e'
my @files = ( "egg_nogg.mp3\n", "egg_nogg\n", "stupid file.ogg.shn
+.flac.mp3\n", "stupid fileloggashnoflacamp3\n" );
foreach my $tmp_name ( @files ) {
print "\$tmp_name = $tmp_name\t=>";
# remove common suffixes
chomp $tmp_name;
for my $suffix ( ".mp3", ".flac", ".shn", ".ogg" ) {
$tmp_name =~ s/$suffix$//;
}
print "\t$tmp_name\n";
}
'
$tmp_name = egg_nogg.mp3
=> egg_
$tmp_name = egg_nogg
=> egg_
$tmp_name = stupid file.ogg.shn.flac.mp3
=> stupid file
$tmp_name = stupid fileloggashnoflacamp3
=> stupid file
That would be better written as:
foreach my $tmp_name (`dcop amarok playlist filenames`) {
$tmp_string .= "[$tmp_idx]\t";
# remove common suffixes
chomp $tmp_name;
$tmp_name =~ s/\.(?:mp3|flac|shn|ogg)\z//;
# and append the filename
$tmp_string .=
( $playing =~ /$tmp_name/ ) ? "*** $tmp_name ***\n" : "$tmp_
+name\n";
$tmp_idx++;
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|