Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Compare two file text input, compare it, replace and write new file

by repellent (Priest)
on Feb 14, 2012 at 06:29 UTC ( [id://953628]=note: print w/replies, xml ) Need Help??


in reply to Compare two file text input, compare it, replace and write new file

You are splitting your source.txt lines with a single whitespace:
my @words = split / /, $s;

For your code to work, source lines have to look like keys separated by single whitespaces.

Hmm.. it seems like split may not be the right tool, since it's hard to specify what to really split on. Try regex search and replace!
# match a backslash followed by two characters, # then compute the replacement by looking into %words $s =~ s{(\\..)}{ $words{$1} || $1 }ge;

Have a look at perlrequick and perlretut. (And follow kcott's advice.)

Replies are listed 'Best First'.
Re^2: Compare two file text input, compare it, replace and write new file
by wa2nlinux (Novice) on Feb 14, 2012 at 23:30 UTC
    the text is already formated, such as
    \ha\hang\hu\hung
    can I using search replace if the format like in the code above ? because the codes sometime having same first or second characters such as \ha and  \hang My code already work but if I manually add a space after the code  \ha\ca\ra\ka to \ha \ca \ra \ka

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-19 05:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found