<?xml version="1.0" encoding="windows-1252"?>
<node id="120742" title="simple regex (again)" created="2001-10-23 10:54:13" updated="2005-08-13 07:28:48">
<type id="115">
perlquestion</type>
<author id="961">
Anonymous Monk</author>
<data>
<field name="doctext">
This works fine for outputing to file, however, still unable to assign to array without opening the output afterwards. Would be good if I could set overall match to array at the same time as sending to output.
&lt;code&gt;
#!perl.exe
my $filename="e:\test.out.txt";
my $output="e:\out.txt";
sub body{
if (-r $filename) {

  open(FILE,"&lt;$filename");
  open(OUTPUT, "&gt; $output");
  while(&lt;FILE&gt;) {
    chomp;

    if (/Datasource:/) { print OUTPUT "\n", $_; }

    if (/Passed:/) { $section="passed"; next; }
    elsif (/Failed:/) { $section="failed"; print OUTPUT "\n",$_; next; }
    elsif (/Exception:/) { $section="except"; print OUTPUT "\n",$_; next; }

    if ($section ne "passed") {
      if (/(test\.)|(Summary:)/) { print OUTPUT "\n",$_; }
    }
  }
  close(FILE);
  close(OUTPUT);
} else {
  print("cant read file ",$filename,"\n");
}
}
&lt;/code&gt;
&lt;p&gt;&lt;font size="-1"&gt;&lt;b&gt;Edit:&lt;/b&gt; [davorg] - added code tags&lt;/font&gt;&lt;/p&gt;</field>
<field name="reputation">
0</field>
</data>
</node>
