Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Parsing HereDocs

by GrandFather (Saint)
on Jun 11, 2008 at 00:32 UTC ( [id://691365]=note: print w/replies, xml ) Need Help??


in reply to Parsing HereDocs

What are you using to parse the source at present? Are you looking for a chunk of code using regexen and loops, or something you can plug into a Parse::RecDescent rule set?

The following sketch code for handling the problem using regexen may help:

use strict; use warnings; while (<DATA>) { s/\[\[(\w+)/parseHereDoc ("$1")/e if /\[\[\w+/; print; } sub parseHereDoc { my $id = shift; my $str = '"'; while (<DATA>) { last if /^$id$/; $str .= $_; } return $str . '"'; } __DATA__ var = [[END . "other stuff"; heredoc data END

Prints:

var = "heredoc data " . "other stuff";

Perl is environmentally friendly - it saves trees

Replies are listed 'Best First'.
Re^2: Parsing HereDocs
by JStrom (Pilgrim) on Jun 11, 2008 at 01:47 UTC
    I've been working with Parse::RecDescent, but I have no problem switching to YAPP or one of the others as I've invested little time in the parsing code so far.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://691365]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-19 12:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found