mel00 has asked for the wisdom of the Perl Monks concerning the following question:
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'.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Copy data from one file and add it to another
by wade (Pilgrim) on Apr 25, 2008 at 22:11 UTC | |
|
Re: Copy data from one file and add it to another
by jwkrahn (Abbot) on Apr 26, 2008 at 02:50 UTC | |
by olus (Curate) on Apr 26, 2008 at 10:47 UTC | |
by Anonymous Monk on Jan 24, 2018 at 09:27 UTC | |
by poj (Abbot) on Jan 24, 2018 at 11:06 UTC | |
by jumdesumit (Novice) on Feb 01, 2018 at 10:31 UTC | |
|
Re: Copy data from one file and add it to another
by apl (Monsignor) on Apr 26, 2008 at 14:48 UTC |