'exists'? Why doesn't it work?

------_=_NextPart_001_01C31893.158D4106
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi everybody,

I'm having a problem using the exists function. I have the following =
code that takes a list of searchwords (@search) and searches texts =
stored in a MySQL database and orders them by relevance.
My idea was that records that contain more than one search word are =
probably more relevant than others.=20
The search results (id, rank) are stored in a hash with id as key and =
rank as the corresponding value. As it may be perfectly possible that an =
id comes up more than once I wanted the values to be multiplied. I use =
exists to determine if an id has already been used. But somehow the code =
below doesn't work the instead of multipliing the two values the old =
value is simply replaced by the new one.=20
What am I doing wrong.=20

Greetings Marcus

---snippet---

foreach(@search){
    my $sql =3D "SELECT id, MATCH (field1,field2) AGAINST ('$_') AS rank =
FROM t2 WHERE MATCH (field1,field2) AGAINST ('$_')";
    print "$sql\n";

    my $sth =3D $dbh->prepare($sql);
    $sth->execute;
    while(my $result =3D $sth->fetchrow_hashref){
	$result->{rank} * $hitlist{$result->{id}} =
if(exists($hitlist{$result->{id}}));=20
	$hitlist{$result->{id}} =3D $result->{rank};
=09
    }
}
---snippet



Marcus Willemsen
Online Redaktion
Juve Verlag GmbH
Sachsenring. 6
50677 K=F6ln
++49 (0)221 91 38 80 16
www.juve.de


Gesch=E4ftsf=FChrer: Dr. Astrid Gerber, Dr. Aled W. Griffiths
Sitz der Gesellschaft: K=F6ln
Amtsgericht K=F6ln HRB 29593, Gerichtsstand: K=F6ln
Bankverbindung: Stadtsparkasse K=F6ln, BLZ 37050198, Kto-Nr. 4772281



------_=_NextPart_001_01C31893.158D4106--
0
marcus
5/12/2003 2:30:49 PM
perl.beginners 29388 articles. 4 followers. Follow

2 Replies
918 Views

Similar Articles

[PageSpeed] 48
Get it on Google Play
Get it on Apple App Store

You're going to kick yourself for this one:

$result->{rank} *=3D $hitlist{$result->{id}}
if(exists($hitlist{$result->{id}}));

Luke
0
Luke
5/12/2003 2:36:13 PM
Marcus Willemsen wrote:
> Hi everybody,
> 
> I'm having a problem using the exists function. I have the
> following code that takes a list of searchwords (@search) and
> searches texts stored in a MySQL database and orders them by
> relevance. My idea was that records that contain more than one search
> word are probably more relevant than others.
> The search results (id, rank) are stored in a hash with id as
> key and rank as the corresponding value. As it may be
> perfectly possible that an id comes up more than once I
> wanted the values to be multiplied. I use exists to determine
> if an id has already been used. But somehow the code below
> doesn't work the instead of multipliing the two values the
> old value is simply replaced by the new one.
> What am I doing wrong.
> 
> Greetings Marcus
> 
> ---snippet---
> 
> foreach(@search){
>     my $sql = "SELECT id, MATCH (field1,field2) AGAINST
> ('$_') AS rank FROM t2 WHERE MATCH (field1,field2) AGAINST ('$_')";  
> print "$sql\n"; 
> 
>     my $sth = $dbh->prepare($sql);
>     $sth->execute;
>     while(my $result = $sth->fetchrow_hashref){
> 	$result->{rank} * $hitlist{$result->{id}}
> if(exists($hitlist{$result->{id}}));
> 	$hitlist{$result->{id}} = $result->{rank};
> 
>     }
> }

Run this through perl -wc and you should spot the problem.
0
Bob_Showalter
5/12/2003 2:38:28 PM
Reply:

Similar Artilces:

''''''''''''''''''''
Name: haznen Email: haznenatyahoodotcom Product: Gran Paradiso Alpha 8 Summary: '''''''''''''''''''' Comments: '''''''''''''''''''''''''''''''''''' Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a1) Gecko/20061204 UGES/1.7.2.0 GranParadiso/3.0a1 From URL: http://www.mozilla.org/projects/granparadiso/ Note to readers: Hendrix gives...

AW: 'exists'? Why doesn't it work?
Gnnnn* Shame on me. Thanks a lot Marcus ...

'do' won't 'do' if '/'
Greetings to All from Au, Have a NetWare Perl 5.8.4 and wanted to tweak File\Spec\NW.pm to try and standardise on '/' separators. If I run a test script (t/uni/lower.t) with an unmodified NW.pm, it calls t/uni/case.pl, that, in case.pl, (when the path separators are '\'), the $file is '..\lib\unicore\To\Lower.pl' and the following code portion works, with $simple getting a returned table: sub casetest { my ($base, $spec, $func) = @_; my $file = File::Spec->catfile(File::Spec->catdir(File::Spec->updir, "lib", &qu...

'''''
Name: mario Email: ramar17atfastwebnetdotit Product: Gran Paradiso Alpha 2 Summary: ''''' Comments: K: Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a2) Gecko/20070206 GranParadiso/3.0a2 ...

Installation 'Sybase DataWindow PS' printer on W98 doesn't work (so PDF export can't work either)
I have a problem with export DataWindow content to PDF on W98 systems. (I don't have any problem with PDF export on other systems like as WINNT, W2K, WXP). I found out that the problem is in the Sybase DataWindow PS printer. It looks like installed but it DOESN'T WORK on W98. When I try print something on this printer then no PostScript file is created. So I tried manual installation of it but it occurs an error during manual installation (I used description of instalation from Bruce Armstrong). The error said that printer driver (PSCRIPT.DLL) can't be loaded. I use...

Firefox doesn't work well in 'User' mode as opposed to 'Administrator' mode
Name: Dave Wintermute Email: dewin59atgmaildotcom Product: Firefox Summary: Firefox doesn't work well in 'User' mode as opposed to 'Administrator' mode Comments: Logging into my account fails on http://www.boynton-beach.org/ in User logon, but works fine in Administrator logon. Similarly, loggin into my account at wireless.att.com fails in the User logon, but works ok in the Administrator logon. I recently downloaded Chrome and discovered that I do not have these problems when logging into my accounts with either of the above sites. I will probably s...

'Tab' control 's visible doesn't work.Why?
I use tab control in my applition. And I set visible=false, but it doesn't work. my code is: ----------------------------------------------- <asp:ScriptManager ID="ScriptManager1" runat="server" />  <div>   <ajaxToolkit:TabContainer runat="server" ID="Tabs" Height="138px" ActiveTabIndex="0"    Width="402px">    <ajaxToolkit:TabPanel runat="server" ID="Panel1" HeaderText="Tab1" Visible="f...

<location> doesn't work when parent directory of path doesn't exist
Hi, I'm having a problem setting up web.config to challenge for authentication on some pages, but not others. Here is what I'm doing:<configuration>...    <system.web>...        <authentication mode="Windows" />        <authorization>            <allow users="*"/>        </authorization>...    </system.web>    <location path="se...

Urgent: AutoCompleteExtender doesn't work/Updatepanel doesn't work
This is my code for the AutoCompleteExtender <asp:textbox id="txtQuickSearch" runat="server" CssClass="inputText" style="width:145px; "></asp:textbox> <atlas:AutoCompleteExtender runat="server" ID="acSearch"> <atlas:AutoCompleteProperties TargetControlID="txtQuickSearch" Enabled="True" ServicePath="http://localhost/Sony.BusinessSuite.Web.UI/AtlasServices/MasterData.asmx" ServiceMethod="GetAllModels" minimumprefixlength="2" /> </atlas:AutoCompleteExtender> When i start typing fiddler shows: # Result Host URL Body Caching Content-Type User-...

Spellchecker doesn't work: no error, just doesn't work
Hey all. This is only happening with one person. It's all GW7 no SP. has worked fine before. Anyway when they type along it doesn't catch that spelling and it doesn't fire up spell check before it's sent like it is checked off to do. It does nothing. It just sends it when you click send; no error, nothing. I did a rebuild, analyze/fix. I have it set at all levels for this user. any ideas Mark, well, I'd try a more recent client version first. GW7 was less than stellar before SP1. Uwe -- Novell Support Connection Volunteer SysOp Please don...

Keyboard shortcut 'ctrl+T' doesn't always work
Name: Georgi Liubenov Email: liubenoffatmaildotbg Product: Firefox Summary: Keyboard shortcut 'ctrl+T' doesn't always work Comments: When pdf document is opened in a tab 'ctrl+T' shortcut doesn't work. I have to go to File -> New Tab to open a tab. Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3 From URL: http://hendrix.mozilla.org/ Note to readers: Hendrix gives no expectation of a response to this feedback but if you wish to provide one you must BCC (not CC) the sender for them to ...

INSTALLSCRIPT doesn't have 'site', 'vendor' values?
Hi, I notice the following in the MakeMaker docs (version 5.91_01): INSTALLDIRS set to perl site vendor PREFIX SITEPREFIX VENDORPREFIX INST_ARCHLIB INSTALLARCHLIB INSTALLSITEARCH INSTALLVENDORARCH INST_LIB INSTALLPRIVLIB INSTALLSITELIB INSTALLVENDORLIB INST_BIN INSTALLBIN INSTALLSITEBIN INSTALLVENDORBIN INST_SCRIPT INSTALLSCRIPT INSTALLSCRIPT INSTALLSCRIPT ...

superreview granted: [Bug 404773] Find bar doesn't like the letters 'b', 'o ', 'd', 'y', and 'random'
Johnny Stenback (:jst) <jst@mozilla.org> has granted Dave Townsend (Mossop) <dtownsend@mozilla.com>'s request for superreview: Bug 404773: Find bar doesn't like the letters 'b', 'o', 'd', 'y', and 'random' https://bugzilla.mozilla.org/show_bug.cgi?id=404773 Attachment 291924: patch rev 1 https://bugzilla.mozilla.org/attachment.cgi?id=291924&action=edit ------- Additional Comments from Johnny Stenback (:jst) <jst@mozilla.org> Nice :) r+sr=jst ...

'do this automatically from now on' doesn't work
Name: Karl Email: death_of_rats_athotmaildotcom Product: Firefox Summary: 'do this automatically from now on' doesn't work Comments: upon downloading for eg a *.torrent or *.mp3 file, when the 'do this automatically from now on' box is checked firefox fails to remember this setting, and displays the dialogue box every time a file is downloaded. Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1 ...

Web resources about - 'exists'? Why doesn't it work? - perl.beginners

Resources last updated: 12/29/2015 11:14:45 PM