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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parse::RecDescent and parsing whole files.

Status
Not open for further replies.

Fadern

Programmer
Joined
May 4, 2007
Messages
3
Location
SE
Hi!

I'm quite new to Perl, however I'm writing a parser for a rather complex debug-file. The format is a quite long specification so I thought it would be best to use a parser module with a grammatics.

I've decided to try out the Parser::RecDescent, but I can't figure out how to parse an entire file. Every tutorial/documentation example I've found are about a single line of input, but I need to pick out data from a large file with the format spanning over multiple lines. In the simpler files the format looks like:

n1
{
n2 {
{n: 3}
n3
{
5
}
}
n4
{
4
}
...
}

Now what part of the RecDescent parser do you use to read a file? Or maybe I've just missed something fundamental about Perl. :)

Thank you for your time!
 
What are you looking for when that file is parsed? What kind of data structure do you want?
 
I'm planning to instantly write it to a XML-file with the corresponding actions defined in the grammatic.

Hope it'll elucidate something for you :)
 
read the file into a scalar and parse the scalar.

Code:
open(FH,"myfile");
my $file = do{local $/; <FH>}:
close(FH):

now you can parse $file.





------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top