Hi I have already tried the way u have told but when i use ' while($line=<IN>)' and the regex in the if loop then the regex pattern is matched only once in the current line and does'nt get repeated for the same line with differnt bookname present in the same line. For Eg. If the input is Genesis 45. with 1 chron .......... here genesis an 1 chron are the book names which can be identified by the function . the output is: <book>Genesis 45. eith 1 chron.......... here the loop does'nt get repeated for 1 chron. Please help in this regard
Dhanashri Bhate <[EMAIL PROTECTED]> wrote: Hi Anand, You know where its going wrong then change it :) Ok, I haven't gone into the regex etc. but I see these 2 major problems: 1. $line=; should be also there inside the while loop, to make the program get the next line in the file, and hence eventually come out of the loop when it reaches EOF. Or, make the change the while loop as "while ( $line = )" and put the regex check in "if" conditional. 2. Again, you want to make some changes to the line you've read, and then print it to the output file, the line "print OUT $line;" should be in the while loop, not outside. See this: while ( $line = { if ($line=~m/([123]?[\.\s]*[a-z\\=\.]+)/oi) { .. ... do what u want if regex matches ... print OUT $line; } } Dhanashri -----Original Message----- From: anand kumar [mailto:[EMAIL PROTECTED] Sent: Monday, January 09, 2006 11:31 AM To: beginners@perl.org Subject: Reading contents of file Hi I am new to PERL. I have a doubt, The following script is used to read the contents of a file (word by word (or) word preceeded by a number), check for the existence of the matched pattern which is done by the help of bookref() sub, if it is found then the matched pattern is prefixed with the tag . When I run the following script it goes to unending because it is not pointing to the next string after the complete execution of the loop . Please correct me open IN, "r1.dat"; open OUT, ">r1.txt"; $/=undef; $line=; while ($line=~m/([123]?[\.\s]*[a-z\\=\.]+)/oi) { $book=$1; print $book,"\n"; $t_book=$book; $t_book=~s/\.//g; $t_book=~s/\\l=([a-z]+)\\/$1/ig; $t_book=~s/<(|\/)(B|I|SC|U)>//ig; $quote=bibref($t_book); if($quote) { $line=~s/($book)/$1/ig; } } print OUT $line; close(IN); Thanks in advance for the help. Regards Anand Send instant messages to your online friends http://in.messenger.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] Send instant messages to your online friends http://in.messenger.yahoo.com