Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
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 ( #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.)


Comment on Re: Compare two file text input, compare it, replace and write new file
Select or Download Code
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
Node Status?
node history
Node Type: note [id://953628]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2014-09-22 00:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (176 votes), past polls