----------------------------------------^^^^^
Are you sure you want to put a whole phase in as a key in %xref? The
keys to %xref are supposed to be words according to the conventions used
so far.
Well no, I just wanted to be able to use the (specific) meaning later on...
---------------------^^^^^^^^
Did you use strict; and use warnings; ? They would have pointed out
that this variable is undef at this point because you changed it from
$meaning to $text two lines above and didn't change it here. If it were
still stored in %meaning, then the text could be gotten back by ID just
by saying $meaning{$id}.
changed it back to meaning again
If you hadn't made the mistake of changing $meaning to $text in all but
one of the places it is used, you could have used $meaning{$id} to get
that text -- just replace the ... with $meaning{$id}. You'd better make
sure the text doesn't contain any ' characters, and perhaps " characters
either. Maybe < and > also? Others? Probably best to run it through a
Javascript quoter, and then an HTML quoter?
Hi Bob. First: my original question and problem is solved, it works perfect
with this code:
open (DB, "<$db_file_name") or &cgierr("error in search. unable to open
database: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
my %xref;
my %meaning;
while ( <DB> ) {
chomp;
my($id, $word, $plural, $synonym,$cat,$meaning) = split /\|/;
@xref{($word, $plural, $synonym)} = ($id)x3;
$meaning{$id}=$meaning;
}
foreach my $id(keys %meaning){
foreach my $word ( $rec{'Text'} =~ /\S+/g ) {
my $newword = "<a
href=\"$db_script_link_url&ID=$xref{$word}&mh=1&ww=1&view_records=1\">$word<
/a>";
$rec{'Text'} =~ s|\b$word\b|$newword|gs if exists $xref{$word};
}
}
close DB;
What it does: when showing the field $rec{'Text'}from one of the records of
the database it checks if words, synonyms or plurals form all records in the
database are used in this field and if so create a link to those words.
Anyway, I don't need telling you people do I?
But just to be clear about
what I'm doning.
Now I wanted something more again (always the same...), when showing records
from another database I wanted it to happen as well. Got that working (the
links), wasn't very hard. However, I now wanted a popup screen as well
already showing the meaning of the word (taken from the meaning field). Now,
here I run into troubles and I think it's because it's still working and
trying to do things with that meaning field as well. If it would produce
just the text it works. I thought it might be ' or " as you suggested so
made sure that I got rid of them. However, that didn't do the trick and the
problem was worse than just that.
So I think $meaning{$id} in this case (underneath) has more luggage than
that what I am looking for. In this case I do not want links in this field
now, I know I want a lot and am still not capable of producing it, quite
frustrating, but hey, this is my way of learning I guess. I'll copy the code
underneath that I tried but that was giving me more than I wanted:
open (DB, "<$db_file_name_abc") or &cgierr("error in search. unable to open
database: $db_file_name_abc.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
my %xref;
my %meaning;
while ( <DB> ) {
chomp;
my($id, $word, $plural, $synonym, $cat, $meaning) = split /\|/;
@xref{($word, $plural, $synonym, $meaning)} = ($id)x4;
$meaning{$id}=$meaning;
}
foreach my $id(keys %meaning){
foreach my $word ( $rec{'Text'} =~ /\S+/g ) {
if ($xref{$word}) {
my $newword = "<a
href=\"$db_dir_url/db.cgi?db=abc&uid=$db_uid&ID=$xref{$word}&mh=1&ww=1&view_
records=1\" class=\"abclink\"
ONMOUSEOVER=\"popup('$meaning{$id}','#ffffcc')\";
ONMOUSEOUT=\"kill()\">$word</a>";
$rec{'Text'} =~ s|\b$word\b|$newword|gs;
}
}
}
close DB;
As soon as I insert $meaning{$id} it all goes wrong, all of it, even $word
isn't what it's supposed to be anymore. As well after cutting out all html
and ' and " etc. from $meaning{$id}.
To all the people (still) reading this: thanks for your patience with me!
Lex