Your skill will accomplish
what the force of many cannot
Iterator to parse multiline string with \\n terminatorby three18ti (Scribe)
|on Oct 06, 2013 at 05:46 UTC||Need Help??|
three18ti has asked for the
wisdom of the Perl Monks concerning the following question:
I would like to parse a file that has single lines split into multiple lines by terminating the line with a "\".
I basically want to read a file line by line and grab all continued lines at once.
I was thinking about something along the lines of:
Where I get stuck is the logic to grab the next line if the line is terminated with a /\\\n/... My first thought was some kind of recursion:
(Maybe I should be using a named sub instead of a closure; eventually I would like to include this as part of an object I'm trying to work out the parsing logic first)
I could just be over thinking the problem...
Thanks for your thoughts
Edit: Some further thinking I tried using a named sub instead of a closure
But each time fh_iterator is called, it's going to clobber $line... So this doesn't do what I'd expect. I'd like to preserve the \ but should probably chomp the $fh->getline somehow.