Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Smartphone/Media Center integration via XMPP over GoogleTalk

by jwkrahn (Monsignor)
on Aug 03, 2009 at 16:35 UTC ( #785500=note: print w/ replies, xml ) Need Help??


in reply to Smartphone/Media Center integration via XMPP over GoogleTalk

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++; }


Comment on Re: Smartphone/Media Center integration via XMPP over GoogleTalk
Select or Download Code
Re^2: Smartphone/Media Center integration via XMPP over GoogleTalk
by mikelieman (Pilgrim) on Aug 03, 2009 at 17:37 UTC
    Thanks for the tip. Luckily, that broken algorithm is just used to produce pretty printed output for displaying playlists. I'll make sure to include the changes into the next revision however.
      The one-line bug has been patched in the code.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2014-10-23 05:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (124 votes), past polls