Hi
   
  I have tried the way u explained, Thanks for that But I have few new problems 
. The code after the modification is as below:
   
  open IN, "r1.dat";
open OUT, ">r1.txt";
$/=undef;
$line=<IN>;
 while($line=~m/([123]?[\.\s]*[a-z\\=\.]+)/cig)
{
 $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)
 {
  print OUT "<bibl>$book";
 }
 else
 {
  print OUT $book," ";
 }
$line=~s/$book//;
 
}
close(IN);
   
  Input:
  Genesis 45. anand 1 chron mca 2 chron
  1 chron kumar
   
  output:
  <bibl>Genesis. anand <bibl>1 chron  mca <bibl>2 chron<bibl>1 chron 
 kumar 

  Here the problems are :
  1) The new line character '\n' cannot be detected.
  2)I am not able to print the unmatched data i.e in the above example '45' 
doesn't match the regex in the while loop so this cannot be printed in the 
output file.
   
  Plz suggest me in the matter . Is there any way to find the data which is 
unmatched with the regex.
   
  Thanks for the help
   
  Regards
  Anand
  
Dhanashri Bhate <[EMAIL PROTECTED]> wrote:
        v\:* {behavior:url(#default#VML);}  o\:* {behavior:url(#default#VML);}  
w\:* {behavior:url(#default#VML);}  .shape {behavior:url(#default#VML);}        
        Ok, got it now J , sorry, I misunderstood your problem earlier.
  If you are expecting multiple matches in a single line, then i would suggest, 
keep the regex match as it is  i.e. while 
($line=~m/([123]?[\.\s]*[a-z\\=\.]+)/oi),
  But inside the loop when you a find a match and do relevant things, modify 
$line in such a way, that you get the next ( may be replace the matched 
substring with empty string? ) This way the lop will end once all matches on 
the line are found.
   
  Well I’m not a Perl expert, so this is what I could think of J But I’m sure 
there must be a better way to do it!
   
  Dhanashri
   
   
   
   
      
---------------------------------
  
  From: anand kumar [mailto:[EMAIL PROTECTED] 
Sent: Monday, January 09, 2006 12:56 PM
To: [EMAIL PROTECTED]; beginners@perl.org
Subject: RE: Reading contents of file

   
    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,
Yo! u 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 conte! nts 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 


  

Send instant messages to your online friends http://in.messenger.yahoo.com 

Reply via email to