I'm not sure I can provide a complete solution, since I have no idea what is comming in on the command line, and what the data is.

You get the filenames into @all_file_names but all you do is to write those to index.txt, you do not appear to do anything else with the files - or maybe I misunderstand.

However you have some strange constructs which tidying up and might make your code clearer.
use strict;
There are several variables that are used inside the main loop. Are these supposed to be globals? Declaring them with my will make their scope clearer (that might solve part of your problem).

In a couple of places you have code like this:
select directory1; print "$path\n";
which is rather unnecessary. It would be simpler to:
print directory1 "$path\n";
Be careful of your opens:
open Contract1, "<./$_ \n"; # What's with the space and new-line? my @lines = <Contract1>; close Contract1; my $contents = join "", @lines;
Perl will look in the current directory anyway (no need for ./), and you should always test the open. Could be written as:
open Contract1, '<', $_ or die "Unable to open $_: $!"; local $/ = undef; # slurp mode my $contents = <Contract1>; # Hope the files are small! close Contract1;
You place an undef element onto the array, then shift it off:
@all = undef; shift @all;
Would be simpler if you did this:
my @all;
Which you would have done if you use strict;

I'm not sure that you actually need to do a multi-line match and store everything, but then again I don't know what the data looks like.

In reply to Re: Reading a Directory of Files, Searching for Text, Outputting Matches by cdarke
in thread Reading a Directory of Files, Searching for Text, Outputting Matches by NorthShore44

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.