<!doctype html public "-//W3C//DTD W3 HTML//EN">
<head><style type="text/css"><!--
blockquote, dl, ul, ol, li { padding-top: 0 ; padding-bottom: 0 }
--></style><title>Re: [slimp3-dev] Modified info functions (for
searchin</title></head><body>
<div>Looks good, if it works as advertised. Glad to have
somebody else attack the regexp stuff.</div>
<div><br></div>
<div>So the only character that would need to be escaped would be *,
right?</div>
<div><br></div>
<div>I'm also interested in the performance, but rumor has it that the
perl rexexp engine is quite fast. We'll probably need
backgroundability anyways.</div>
<div><br></div>
<div>-dean</div>
<div><br></div>
<div><br></div>
<blockquote type="cite" cite>I did some testing, and the songs()
function wasn't working as desired <br>
(mainly due to me not looking at what the genreCache structure was
like)<br>
<br>
Here is an additional function and a corrected songs() which do work.
I'd <br>
like some comments before I check it in.<br>
<br>
sub filterHashByValue {<br>
<x-tab> </x-tab>my ($pattern,
$hashref) = @_;<br>
<x-tab> </x-tab>if (!defined($hashref)) {<br>
<x-tab>
</x-tab><x-tab>
</x-tab>return;<br>
<x-tab> </x-tab>}<br>
<x-tab> </x-tab>if
(!defined($pattern) || $pattern eq '*') {<br>
<x-tab>
</x-tab><x-tab>
</x-tab>return keys %{$hashref};<br>
<x-tab> </x-tab>}<br>
<x-tab> </x-tab>my
@filtereditems;<br>
<x-tab> </x-tab>#the following
transformations assume that the pattern provided uses * to <br>
indicate<br>
<x-tab> </x-tab>#matching any character
0 or more times, and that . ^ and $ are not escaped<br>
<x-tab> </x-tab>$pattern =~ s/\(\?\{.*\}\)//g;
#strip executables from $pattern<br>
<x-tab> </x-tab>$pattern =~ s/(\.|\^|\$)/\\$1/g; #escape ., ^ and $ in
$pattern<br>
<x-tab> </x-tab>$pattern =~ s/^(.*)$/\^$1\$/; #add beginning and end
of string requirements<br>
<x-tab> </x-tab>$pattern =~ s/\*/\.\*/g; #use
the regex for matching any character 0 or <br>
more times<br>
<x-tab> </x-tab>my $regexpattern =
qr/$pattern/i; #compiles the regex for multiple uses <br>
(case insensitive)<br>
<x-tab> </x-tab>my ($k,$v);<br>
<x-tab> </x-tab>while (($k,$v) = each
%{$hashref}) {<br>
<x-tab>
</x-tab><x-tab> </x-tab>if
($v =~ $regexpattern) {<br>
<x-tab>
</x-tab><x-tab>
</x-tab><x-tab> </x-tab>push
@filtereditems, $k;<br>
<x-tab>
</x-tab><x-tab>
</x-tab>}<br>
<x-tab> </x-tab>}<br>
<x-tab> </x-tab><br>
<x-tab> </x-tab>return
@filtereditems;<br>
}<br>
<br>
sub songs {<br>
<x-tab> </x-tab>my $genre = shift;<br>
<x-tab> </x-tab>my $artist = shift;<br>
<x-tab> </x-tab>my $album = shift;<br>
<x-tab> </x-tab>my $track = shift;<br>
<br>
<x-tab> </x-tab>my @alltracks = ();<br>
<br>
<x-tab> </x-tab>$::d_f && print
"songs: $genre - $artist - $album - $track\n"<x-tab>
</x-tab>;<br>
<x-tab> </x-tab><br>
<x-tab> </x-tab>foreach my
$g (filter($genre,keys %genreCache)) {<br>
<x-tab>
</x-tab><x-tab>
</x-tab>foreach my $art (filter($artist,keys %{$genreCache{$g}}))
{<br>
<x-tab>
</x-tab><x-tab>
</x-tab><x-tab>
</x-tab>foreach my $alb (filter($album,keys %{$genreCache{$g}{$art}}))
{<br>
<x-tab>
</x-tab><x-tab>
</x-tab><x-tab>
</x-tab><x-tab> </x-tab>my
%songs = ();<br>
<x-tab> </x-tab><x-tab>
</x-tab><x-tab>
</x-tab><x-tab>
</x-tab>foreach my $trk (values %{$genreCache{$g}{$art}{$alb}}) {<br>
<x-tab>
</x-tab><x-tab>
</x-tab><x-tab>
</x-tab><x-tab>
</x-tab><x-tab>
</x-tab>$songs{$trk} = title($trk);<br>
<x-tab>
</x-tab><x-tab>
</x-tab><x-tab>
</x-tab><x-tab>
</x-tab>}<br>
<x-tab>
</x-tab><x-tab>
</x-tab><x-tab>
</x-tab><x-tab> </x-tab>push
@alltracks, filterHashByValue($track,\%songs);<br>
<x-tab>
</x-tab><x-tab>
</x-tab><x-tab>
</x-tab>}<br>
<x-tab>
</x-tab><x-tab>
</x-tab>}<br>
<x-tab> </x-tab>}<br>
<x-tab> </x-tab>return
sortTrackUniq(@alltracks);<br>
}<br>
------------------------ Yahoo! Groups Sponsor
---------------------~--><br>
Sponsored by VeriSign - The Value of Trust<br>
Do you need to encrypt all your online transactions? Find<br>
the perfect solution in this FREE Guide from VeriSign.<br>
http://us.click.yahoo.com/vCuuSA/UdiDAA/yigFAA/rIp0lB/TM<br>
---------------------------------------------------------------------<span </span>~-><br>
<br>
To unsubscribe from this group, send an email to:<br>
slimp3-dev-unsubscribe-***@public.gmane.org<br>
<br>
<br>
<br>
Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/ </blockquote>
<blockquote type="cite" cite><br></blockquote>
<blockquote type="cite" cite><br></blockquote>
<blockquote type="cite" cite>Attachment converted: firebook:Info.pm 1
(PMpm/GKON) (000B80A1)</blockquote>
<div><br></div>
</body>
</html>