shoura has asked for the wisdom of the Perl Monks concerning the following question:
The result file r.txt should be : The Original series began in 1864 and continues to the present serieszzgoodzznicezzsummer nightzzpresentzzfriends. (...) My problem is that my script doesn't read all lines in file a.txt and in the result this add "zz" just between two first wordsseries good nice summer night present friends ....
#!/usr/bin/perl open FILE1,"./a.txt" or die "Cannot open a.txt"; open FILE2,"./b.txt" or die "Cannot open b.txt"; open FILE3,">./r.txt" or die "Cannot create r.txt"; while (<FILE1>) { chomp; /[^\ ]*$/; $common = $&; $begin = $`; chop $begin; $array{$common} = $begin; } close FILE1; while (<FILE2>) { chomp; /^[^\ ]*\ /; $common = $&; chop $common; $end = $'; print FILE3 "$array{$common} $common\zz$end" if exists $array{$commo +n}; } close FILE2; close FILE3;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Insert and attach sequence of words in txt file if it exist in other file
by poj (Abbot) on May 13, 2017 at 19:43 UTC | |
by shoura (Novice) on May 13, 2017 at 20:35 UTC | |
by poj (Abbot) on May 13, 2017 at 20:40 UTC | |
by shoura (Novice) on May 13, 2017 at 20:44 UTC | |
by poj (Abbot) on May 13, 2017 at 20:48 UTC | |
|