Hi,
I am trying to read in a file using the angle operator and then use regular expressions to look for the phrase [PASSED]. I read in the file as one big chunk setting $/ to UNDEF. My regular expression although valid was not working when I ran my perl program. When I tried getting the file printed out when it was read in I found that although [PASSED] was present in the original file when read it the []'s had been stripped and it was now simply PASSED. Unfortunately there are other PASSED's in the file so I cant match for PASSED.
I am reading in a regular .txt file that is only about 15 lines long. The simple code I am using is shown below, why is this happening and what can I do to stop the []'s been stripped.
Thanks,
John
Code:
local $/ = undef;
my $file = "summary2.txt";
open FHANDLE, "< $file" || die "Unable to open $file: $!";
$_ = <FHANDLE>;
if (/\[PASSED\]/) {
print "passed\n";
} elsif (/\[FAILED\]/) {
print "failed\n";
} else {
print "not working\n";
}
I am trying to read in a file using the angle operator and then use regular expressions to look for the phrase [PASSED]. I read in the file as one big chunk setting $/ to UNDEF. My regular expression although valid was not working when I ran my perl program. When I tried getting the file printed out when it was read in I found that although [PASSED] was present in the original file when read it the []'s had been stripped and it was now simply PASSED. Unfortunately there are other PASSED's in the file so I cant match for PASSED.
I am reading in a regular .txt file that is only about 15 lines long. The simple code I am using is shown below, why is this happening and what can I do to stop the []'s been stripped.
Thanks,
John
Code:
local $/ = undef;
my $file = "summary2.txt";
open FHANDLE, "< $file" || die "Unable to open $file: $!";
$_ = <FHANDLE>;
if (/\[PASSED\]/) {
print "passed\n";
} elsif (/\[FAILED\]/) {
print "failed\n";
} else {
print "not working\n";
}