I have not looked at your code carefully but this is what i understand from your description. You have bunch of keywords to be replaced (stored in one file). Then you check for them in another file (2nd file) and write it out to a 3rd file. The code below should get you started. I have not taken care of all the details but it should give you enough idea on how to make changes to the code -

NOTE: Code not tested

#!/usr/bin/perl -w my %lookup = (); # Construct the lookup table while (<INFO>) { chomp; my @list = split; # assuming space separated $lookup{$list[0]} = $list[1]; # search => replace } # Go through the search file and check for lookup strings using # the hash and replace it with the hash-value while (<SRCHFILE>) { for my $k (keys %lookup) { s/$k/$lookup{$k}/g; } print; }

Picking a keyword from a file and then searching for it in the other file and re-reading them it very inefficient. If the first file is manageable i would use a hash as in above example


In reply to Re: trouble matching by sk
in thread trouble matching by cravena

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.