<?xml version="1.0" encoding="windows-1252"?>
<node id="785500" title="Re: Smartphone/Media Center integration via XMPP over GoogleTalk" created="2009-08-03 12:35:25" updated="2009-08-03 12:35:25">
<type id="11">
note</type>
<author id="540414">
jwkrahn</author>
<data>
<field name="doctext">
&lt;blockquote&gt;&lt;i&gt;&lt;c&gt;
    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++;
    }
&lt;/c&gt;&lt;/i&gt;&lt;/blockquote&gt;

&lt;p&gt;
Your algorithm is broken, see for example:
&lt;/p&gt;

&lt;c&gt;
$ 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=&gt;";
        # 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
        =&gt;      egg_
$tmp_name = egg_nogg
        =&gt;      egg_
$tmp_name = stupid file.ogg.shn.flac.mp3
        =&gt;      stupid file
$tmp_name = stupid fileloggashnoflacamp3
        =&gt;      stupid file

&lt;/c&gt;

&lt;p&gt;
That would be better written as:
&lt;/p&gt;

&lt;c&gt;
    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++;
    }

&lt;/c&gt;
</field>
<field name="root_node">
785470</field>
<field name="parent_node">
785470</field>
</data>
</node>
