Ok sorry for an unclear question here my problems I have 3 files : source.txt, target.txt and data. Data file contain 2 column separate by :, example for code below is /hang:code1 /hung:code2 /hong:code3 then source.txt is file text that I want to process it, I need to read all lines and compare to the data file, the source.txt is guarantee have code such as \hang \hung \hing etc (left side code from data file) then those code are replace by code1, code2 etc and write to target file ( target.txt)
#!/usr/bin/perl use strict; use warnings; my $filename = 'data'; my $sfilename = 'source.txt'; my $tfilename = 'target.txt'; open(DFILE, $filename) or die "Could not read from $filename, program +halting."; open(SFILE, $sfilename) or die "Could not read from $filename, program + halting."; open(TFILE, "> $tfilename") || die("Cannot Open File"); while(my $SBR=<DFILE>) { my @fields = split(':', $SBR); my $rRegex = qr/$fields[0]/; my $Regexr = qr/$fields[1]/; for my $s (qw(/hang /hung /hing /heng)) { #here I need read it + as a source file, compare to data file if ($s =~ $rRegex){ print TFILE "$fields[1] "; # then write it to target file } } } close DFILE; close SFILE; close TFILE;

In reply to Re^4: Find Replace text with list by wa2nlinux
in thread Find Replace text with list by wa2nlinux

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.