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";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Parsing HereDocs
by JStrom (Pilgrim) on Jun 11, 2008 at 01:47 UTC |