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

In reply to Unknow number show up by Vkhaw

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.