There are 5 rtf files and 3 txt files ... The rtf file name is mentioned in any one txt file . Im trying to print the rtf file name and the corresponding txt file name.. the snippet is

foreach $file (glob('*.rtf')) { open(my $fh, $file) or die("Unable to open '$file': $!"); while (my $line = <$fh>) { if ($line =~ m/(Apple|Orange|Litchi)/i) { $Sheet->Cells($row,$col-1)->{'Value'} = $file; } } foreach my $files (glob('*.txt')) { open(my $fh1, $files) or die("Unable to open '$files': $!"); if ( grep /$file/i, <$fh1> ) { $Sheet->Cells($row,$col+1)->{'Value'} = $files; } else { $Sheet->Cells($row,$col+1)->{'Value'} = "No Text Files"; } $row=$row+1; close $fh1; } close($fh); }
The ouput im expecting is as follows:- RTF File Name TXT File Name 1 No Text Files 2 a 3 No Text Files 4 b 5 c

1,2,3,4,5 are the rtf file names and a,b,c are the text file names...2 is present in a.txt so it is printed along with 2 similarly for 4 and 5...1 and 2 arent traced so No text files is displayed..but the output what im getting is

RTF File Name TXT File Name 1 No Text Files No Text Files No Text Files 2 a No Text Files No Text Files 3 No Text Files No Text Files No Text Files 4 No Text Files b No Text Files 5 No Text Files No Text Files c

i.e every file is opened and No text file is repeated based upon the no of txt file ..how to break the loop..


In reply to GREP ISSUE by stallion

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.