apl, Yes i realised that after i posted my reply...let me try to get what i had back up


File 1

------

trigger1|TEXT TO BE REPLACED

trigger2|TEXT TO BE REPLACED

trigger3|TEXT TO BE REPLACED

trigger4|TEXT TO BE REPLACED

trigger5|TEXT TO BE REPLACED

File 2

-------

combination1

combination2

combination3
Ouput.txt
---------

trigger1 combination1

trigger2 combination2

trigger3 combination3

trigger4 combination1

trigger5 combination2

My Code #!/usr/bin/perl my $infile1='test.txt'; my $infile2= ; my $outfile= 'output.txt'; open(INFO,"<$infile1") or die "could not open '$infile1; open(FILEA,"outputfromvariantparser1.txt") or die "could not open file +"; open(FILEB,"<<output.txt") or die "could not open file"; my @raw_data=<Filea>; while(my $line=<INFO>) { chomp($line); foreach $combination(@raw_dat) { $line=~s/TEXT TO BE REPLACED/$combination/s; } print Fileb $line; }

WADE - No this is not homework and i am new to perl and am just starting to learn it...and yes i know that my code is not doing what i want it to...it was only using the first combination from the second file and using that to substitute the text in the first file(tried to figure this out for a week before i got on here to ask for help). I was not sure if i was accessing the array elements correctly and thats why i was looking for help...thank you for your pointers i will keep that in mind.

jwkrahn: thank you so much for your help...can i ask how $raw_data[0] works?? i am not clear on how to access array elements and would appreciate it if you can explain that and lastly why is it that you are using 'push' and 'pop'.


In reply to Copy data from one file and add it to another by mel00

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.