in reply to Re: Compare two file text input, compare it, replace and write new file
in thread Compare two file text input, compare it, replace and write new file
having source.txt :#!/usr/bin/perl use strict; use warnings; my $dfile = 'data'; my $sfile = 'source.txt'; my $tfile = 'target.html'; open DFILE, '<', $dfile or die "can not open '$dfile' because: $!"; open SFILE, '<', $sfile or die "can not open '$sfile' because: $!"; open TFILE, '>', $tfile or die "can not open '$tfile' because: $!"; my %words; while (<DFILE>) { chomp; my ($key, $val) = split /:/; $words{$key} = $val; }; while ( <SFILE> ) { my @words = split /(?=\\)/; for my $word ( @words ) { $word = $words{ $word } if exists $words{ $word }; } print TFILE "@words\n<br>"; } close(SFILE); close(DFILE); close(TFILE);
the last character of line (\tl) not replace by value on data. The result in target.html is :\ca\ra\ka\tl \ca\ra\ka\tl
ਕ ਖ ਗ \tl <br>ਕ ꤖ ਗ \tl
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Compare two file text input, compare it, replace and write new file
by wa2nlinux (Novice) on Feb 15, 2012 at 13:12 UTC |