Replacement of sentence in perl


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replacement of sentence in perl
# 1  
Replacement of sentence in perl

Hi,

I have 3 arrays:

Code:
@arr1=("Furthermore, apigenin treatment increased the level of association of the RNA binding protein HuR with endogenous p53 mRNA","one of the mechanisms by which apigenin induces p53 protein expression is enhancement of translation through the RNA binding protein HuR","Here we further demonstrated that the increase in p53 protein level induced by apigenin treatment of 308 keratinoyctes");

@arr2=("Furthermore, apigenin treatment increased the level of association of the RNA binding protein HuR with endogenous p53 mRNA","one of the mechanisms by which apigenin induces p53 protein expression is enhancement of translation through the RNA binding protein HuR");

@arr3=("Moreover, apigenin treatment of cells induced p16 protein expression, which in turn was correlated with cytoplasmic localization of HuR induced by apigenin","nhancement of p53 expression in keratinocytes by the bioflavonoid apigenin");

First i want to compare @arr1 and @arr2 if its matching i want to replace with @arr3 contents.

Here is the code.

Code:
foreach $str1(@arr1)
{
   foreach $str2(@arr2)
	{
		if($str1=~/$str2/)
                 {
                      print "<br> matched <br>";
		      foreach $str3(@arr3)
			{
				$str1=~s/$str1/$str3/ig;		
			}
		
		 }

	}
	print "<br> *** $str1 <br>";
}

Output i got was like this:

Code:
Enhancement of p53 expression in keratinocytes by the bioflavonoid apigenin

Moreover, apigenin treatment of cells induced p16 protein expression, which in turn was correlated with cytoplasmic localization of HuR induced by apigenin

Enhancement of p53 expression in keratinocytes by the bioflavonoid apigenin

But the desired output what i should get should be like this:

Code:
Moreover, apigenin treatment of cells induced p16 protein expression, which in turn was correlated with cytoplasmic localization of HuR induced by apigenin

Enhancement of p53 expression in keratinocytes by the bioflavonoid apigenin 

Here we further demonstrated that the increase in p53 protein level induced by apigenin treatment of 308 keratinoyctes

Any ideas like how can i get this?

I am not able to replace the sentence properly!!

How can substitute the matched contents?

I tried to assign the values also but it didn't work!!!

can i hide the sentence??

With regards
Vanitha

Last edited by vanitham; 11-28-2008 at 07:54 AM..
# 2  
You were close. I think this should work.
Code:
for (my $i=0; $i <= $#arr1; ++$i) 
{
		if($arr1[ $i ] eq $arr2[ $i ])
                {
                      print "<br> $i matched <br>";
                }
                else { 
                      $arr1[ $i ] = $arr3[ $i ];
                      print "<br> $i replaced <br>";
		}
}
foreach $str1 (@arr1) { 
	print "<br> *** $str1 <br>";
}

If you want to use foreach () then you should also shift @arr2 each time.
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #653
Difficulty: Easy
Rocky Raccoon is the mascot of MINIX 3.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sentence delimiter in perl: modifications needed

Hello, I found this Perl Script on the EuroParl website which does Sentence Splitting. #!/usr/bin/perl -w # Based on Preprocessor written by Philipp Koehn binmode(STDIN, ":utf8"); binmode(STDOUT, ":utf8"); binmode(STDERR, ":utf8"); use FindBin qw($Bin); use strict; my $mydir =... (0 Replies)
Discussion started by: gimley
0 Replies

2. Shell Programming and Scripting

Word replacement in Perl

I have the following string : Cat dog fox catepillar bear foxy I need to replace "cat" and "fox" words from this sentence to word "animal" I do the following: $Str1="cat"; $Str2="fox"; $NewStr="animal"; open(F1, "<$inputFile") or die "Error: $!"; open(F2, ">$outputFile") or... (1 Reply)
Discussion started by: AIX_30
1 Replies

3. Shell Programming and Scripting

Perl Array Elements Replacement

Hello, I have the following perl array: @longname = (Fasthernet0/0 Fasthernet0/1 Serial0/1/0 Serial0/2/1 Tunnel55 Tunnel77) with the followinh array: @shortname = (Fa0/0 Fa0/1 Se0/1/0 Se0/2/1 Tu55 Tu77) in other words, I need to remove the following from each element in the array... (4 Replies)
Discussion started by: ahmed_zaher
4 Replies

4. Shell Programming and Scripting

need a perl replacement for this double for loop

hi everybody, can you help me with this? important: it has to be a pure perl code. zz.lis: accessibility arabic archivers astro audio benchmarks . . . "ls accessibility | grep -v Makefile" outputs accerciser at-poke at-spi at-spi-reference (6 Replies)
Discussion started by: pseudocoder
6 Replies

5. UNIX for Dummies Questions & Answers

Script to ask for a sentence and then count number of spaces in the sentence

Hi People, I need some Help to write a unix script that asks for a sentence to be typed out then with the sentence. Counts the number of spaces within the sentence and then echo's out "The Number Of Spaces In The Sentence is 4" as a example Thanks Danielle (12 Replies)
Discussion started by: charlie101208
12 Replies

6. Shell Programming and Scripting

How to remove duplicate sentence/string in perl?

Hi, I have two strings like this in an array: For example: @a=("Brain aging is associated with a progressive imbalance between intracellular concentration of Reactive Oxygen Species","Brain aging is associated with a progressive imbalance between intracellular concentration of Reactive... (9 Replies)
Discussion started by: vanitham
9 Replies

7. Shell Programming and Scripting

perl as awk replacement in a script.

Hey all, Im trying to write a script on windows, which Im not too familiar with. Im generally a bash scripting guy but am using perl for this case. My question is... I have this exact output: 2 Dir(s) 6,380,429,312 bytes free and I just need to get the number out... (4 Replies)
Discussion started by: trey85stang
4 Replies

8. Shell Programming and Scripting

Replacement for eval in Perl??????

I used the eval command in shell programming for assigning a value to a stored value of a variable. Example: VAR="Unix_Id" eval $VAR="101" eval echo $"$VAR" How can i assign a value to a stored value of a variable in perl OR how i can write above code in Perl? I need your help... (4 Replies)
Discussion started by: kunal_dixit
4 Replies

9. Shell Programming and Scripting

Replacement of sed with perl

Hi using the below cmd i am identifying wheether last character in each line in thousands of files as semicolon or not.If last character is semicolon i am removing semicolon .If last character is not semicolon then i am appending next line to present line . For example my input file consists of... (4 Replies)
Discussion started by: dbsurf
4 Replies

10. Shell Programming and Scripting

String Replacement with Perl

I want to replace a string within a file using perl. We have a line that gets commented out, and I want to replace that line now matter how it was commented out. for example, I'd want to replace ###ES=PR1A with ES=PR1A or ##LJW(9/16/26)ES=PR1A with ES=PR1A I tried: perl... (4 Replies)
Discussion started by: Lindarella
4 Replies

Featured Tech Videos