Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^3: Find Replace text with list

by Anonymous Monk
on Feb 08, 2011 at 07:27 UTC ( [id://886893]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Find Replace text with list
in thread Find Replace text with list

How could I qw each line of file?

That doesn't compute. What is the input you have, and what is the output you want? How do I post a question effectively?

Replies are listed 'Best First'.
Re^4: Find Replace text with list
by wa2nlinux (Novice) on Feb 09, 2011 at 01:53 UTC
    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;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-04-23 23:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found