Vkhaw has asked for the wisdom of the Perl Monks concerning the following question:
I am new to perl and I written a script performing split in file 1, then using the particular pattern to search and paste in file 2. However, there is series of number show up in my file 2 which auto added that not belong to file 1/2. Could you please help me point out where is the bug? As it is seem a series of 1-9 adding to the search pattern. This is critical as it is urgent to perform data analysis.
#!/usr/bin/perl #Copy Die2 as Output file use File::Copy; copy ("Die2.txt","CombineDie1Die2.txt") or die "copy failed: $!"; #Open Die1 Input file open (Label, "Die1.txt") or die "can't open Die1: $!"; #Search and replace using 1 liner command while (<Label>) { $replace = $_; chomp ($replace); @temp = split (/,/, $replace); $search = $temp[0].",".$temp[1]; $command_line = "perl -pi\.bak -e s\/".$search."\/".$replace."\/g\ +; CombineDie1Die2.txt"; system ($command_line); }
input file 1 WL,BL,Die1 WL0,BL0,1708 WL0,BL1,1708 WL0,BL2,1708 WL0,BL3,1931 WL0,BL4,1931 WL0,BL5,1931 WL0,BL6,1931 WL0,BL7,1931 WL0,BL8,1708 WL0,BL9,1931 WL0,BL10,1708 WL0,BL11,1708 WL0,BL12,1708 WL0,BL13,1931 WL0,BL14,1931 WL0,BL15,1931 WL0,BL16,1931 WL0,BL17,2153 WL0,BL18,2153 input file 2 WL,BL,Die 2 WL0,BL0,1708 WL0,BL1,1708 WL0,BL2,1708 WL0,BL3,1931 WL0,BL4,1931 WL0,BL5,1931 WL0,BL6,1931 WL0,BL7,1931 WL0,BL8,1708 WL0,BL9,1931 WL0,BL10,1708 WL0,BL11,1708 WL0,BL12,1708 WL0,BL13,1931 WL0,BL14,1931 WL0,BL15,1931 WL0,BL16,1931 WL0,BL17,2153 WL0,BL18,2153 Error output : (example: at line 12, "WL0,BL1,17080,1708" the 3rd value had addition +"0" added in it. Thus, subsequently there was increment of the number + in this area." WL0,BL1,17081,1708 <-- 1708 instead of 17081 WL0,BL1,17082,1708 <-- 1708 instead of 17082 WL0,BL1,17083,1931 <-- 1708 instead of 17083 ========================== Exact Error output file WL,BL,Die1,Die 2 WL0,BL0,1708,1708 WL0,BL1,1708,1708 WL0,BL2,1708,1708 WL0,BL3,1931,1931 WL0,BL4,1931,1931 WL0,BL5,1931,1931 WL0,BL6,1931,1931 WL0,BL7,1931,1931 WL0,BL8,1708,1708 WL0,BL9,1931,1931 WL0,BL1,17080,1708 WL0,BL1,17081,1708 WL0,BL1,17082,1708 WL0,BL1,17083,1931 WL0,BL1,17084,1931 WL0,BL1,17085,1931 WL0,BL1,17086,1931 WL0,BL1,17087,2153 WL0,BL1,17088,2153
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unknown numbers show up
by Athanasius (Archbishop) on Apr 12, 2015 at 14:48 UTC | |
by Vkhaw (Novice) on Apr 12, 2015 at 15:49 UTC | |
by Athanasius (Archbishop) on Apr 12, 2015 at 16:02 UTC | |
by Vkhaw (Novice) on Apr 12, 2015 at 16:24 UTC | |
|
Re: Unknow number show up
by flexvault (Monsignor) on Apr 12, 2015 at 14:40 UTC | |
by Vkhaw (Novice) on Apr 13, 2015 at 16:04 UTC | |
by flexvault (Monsignor) on Apr 13, 2015 at 17:44 UTC | |
|
Re: Unknow number show up
by ww (Archbishop) on Apr 12, 2015 at 15:53 UTC |