NorthShore44 has asked for the wisdom of the Perl Monks concerning the following question:
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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Writing to an Excel file
by biohisham (Priest) on Oct 20, 2009 at 19:32 UTC | |
by Bloodnok (Vicar) on Oct 20, 2009 at 20:19 UTC | |
by Ratazong (Monsignor) on Oct 21, 2009 at 06:10 UTC | |
by Marshall (Canon) on Oct 22, 2009 at 06:52 UTC | |
by kikuchiyo (Hermit) on Oct 22, 2009 at 09:53 UTC | |
by biohisham (Priest) on Oct 22, 2009 at 10:37 UTC | |
|
Re: Writing to an Excel file
by VinsWorldcom (Prior) on Oct 21, 2009 at 14:21 UTC |