O Monks-

I'm writing a program that searches pushes a set of text files into an array, then searches through each file of the array for keyword matches. The way I have the program written now, I pull the text match and the text around it and push it to an outfile, then move on to the next file. Now, instead of pushing the text match to an output file, I only want to create one excel spreadsheet with two columns: one with the file name and one that can take on values of Y or N, depending on whether or not the file contains the keyword match.

Here's the code:

foreach $list (@list) { if ($list =~ m/\/if\/home\/m1hrb00\/covenants\/Contracts\/(.*)\.tx +t/) { #select the index of contract names, trim off the filepath push (@contract_list, $1); print STDERR "$1 \n"; } } $beforecount = 10; + #set how many lines before the match you'd like to pull; $aftercount = 10; + #set how many lines after the match you'd like to pull; foreach (@contract_list) { + #pull in the array of contracts open Contract1, "<./$_.txt \n"; @lines = <Contract1>; close Contract1; my $contents = join "", @lines; @all = undef; shift @all; #loop for Governance + + $infile = "$_"; my $incontract = "$infile".".txt"; print STDERR "$incontract read \n"; while ($contents =~ m/Governance/i) { if ($contents =~ m/((\n.*){$beforecount}Governance(.*\n){$aftercou +nt})/i) { push (@all, "$1\n"); print STDERR "$1\n"; $contents =~ s/Governance//i; $contract = "$_"; my $outfile = "$contract".".txt"; open (Contract1a, ">", "/if/home/m1hrb00/covenants/CorporateGo +vernance/Governance/$outfile") || die("Cannot open output file $outfile: $!"); print Contract1a join("\n", (@all)); print STDERR "$outfile matched \n"; close Contract1a;

I want to add at the end another line to do what I mentioned above. Thanks!


In reply to Writing to an Excel file 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.