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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |