Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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

by belize (Deacon)
on Dec 01, 2000 at 22:35 UTC ( [id://44430]=note: print w/replies, xml ) Need Help??


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

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?

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

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

    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

      The code:

      /([^|]+)\|(.*)/; $keywords{$1} = $2;
      should really be:
      /([^|])\|(.*)/ and $keywords{$1}=$2;
      - never use $1 and friends unless you actually get a match, or your results may be unpredictable.
      Thanks arturo, I'll work through the code and give it a try.

      Appreciate your input.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-20 07:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found