in reply to Re: Auto linking to words in a text file
in thread Auto linking to words in a text file

This is pretty much what I mean. I envision a text file with all the words needed to be linked to thus:

link_word|link_URL

Then when "link_word" appears in a returned text, anywhere that "link_word" appears, it would be replaced with:

link_word

Hope this is more clear.

  • Comment on Re: Re: Auto linking to words in a text file

Replies are listed 'Best First'.
Re: Re: Re: Auto linking to words in a text file
by arturo (Vicar) on Dec 01, 2000 at 22:29 UTC

    I'm still not getting it, I'm afraid. Would this be defined at the top of a file, as in "here's a list of words and their associated links" or *within* the file, as in only certain occurrences of the words will get linked, and that link is determined by what follows the 'pipe' symbol.

    Example #1

    cult|http://www.slashdot.org banana|/orange.html Being in a cult can reduce your ability to eat a banana, doctors claim +.

    Example #2

    Being in a cult|http://www.slashdot.org can reduce your ability to eat + bananas|/orange.html , doctors claim.

    if the latter, it's so close to HTML already it's almost not worth the work of writing a script. But whatever. If the former, what you could to do is read the word/url pairs into a hash, and do something like what I suggested above. Philosophy can be made out of anything. Or less -- Jerry A. Fodor

      Example #1 is what I want.

      I don't expect the link file to be more than 50 or 60 pairs.

      Any idea what kind of overhead on CPU this might have if the returned text file is about 7000 characters in size?

        Basic code (assuming the file you're reading consists *ONLY* of word/link pairs on a single line ... I'd suggest separating them with something other than a pipe, too, but whatever.)

        # assuming the link data file is open my $keywords; while (<LINKDATA>) { # regex matches (everything to the left of the pipe), puts # it in $1, then (everything to the right of the pipe) # and puts that in $2 /([^|]+)\|(.*)/; $keywords{$1} = $2; }

        This should be reasonably efficient in terms of speed and not so bad on memory if your list of words isn't too large.
        HTH,

        Philosophy can be made out of anything. Or less -- Jerry A. Fodor