Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

metacharacters stripped out when inputting from file

Status
Not open for further replies.

damonh78

Programmer
Jul 28, 2005
44
IE
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";
}
 
As you say, if the [ and ] characters are read in ok, the script above works fine.

I doubt that there's enough information above for anyone else to resolve the issue. As it appears to relate to the datafile being input, I think we need to see it.
 
perl does not strip meta characters from text files unless you code it to do that. You have correctly escaped the square brackets in your regexp so perl will treat them as literal square brackets instead of character class delimiters. Can we see a few lines of the input file?
 
sorry tonykent,

you posted while I tried a couple of things, otherwise I would not have duplicated your comments.
 
sure thing its just a regular text file called summary.txt which is generated by another perl script:

--- Start - Names test suite result summary - Start ---

Testcase for bug12000077results.txt PASSED
check file bug12000077results.txt for more details

Testcase for lbJ_12.txt PASSED
check file lbJ_12.txt for more details

Testcase for ns_lb_masteroutputCPP PASSED
check file ns_lb_masteroutputCPP for more details

Testcase for ns_lb_masteroutputJ PASSED
check file ns_lb_masteroutputJ for more details

Testcase for /ns_masteroutputCPP/ PASSED
check file ns_masteroutputCPP for more details

Testcase for ns_masteroutputJ PASSED
check file ns_masteroutputJ for more details

heck file bug67756.txt for more details

Testcase for iiop_poop.txt PASSED
check file iiop_poop.txt for more details



[PASSED] All tests with and without SSL passed


--- End - Names test suite result summary - End ---

 
Well that's weird... works fine here, and the file doesn't have the metacharacters stripped.

As a thought, do you have access to the other script to possibly change the '[PASSED]' to something like '*** PASSED ***' and then check for that instead ?
 
with your exact code and your exact file it works OK for me. Not sure what to tell you, but the problem must be elsewhere.
 
Cheers guys,

Thats strange, no unfortunately cant change the [PASSED]. I will try it again with a fresh head this morning and see if it does the same, if so I can always use a different exression to look for.

Thanks again,

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top