|Welcome to the Monastery|
Handling different sections in config filesby pzbagel (Chaplain)
|on May 15, 2003 at 03:36 UTC ( #258322=perlquestion: print w/replies, xml )||Need Help??|
pzbagel has asked for the wisdom of the Perl Monks concerning the following question:
I have a configuration file which is broken down into sections, each section is different and gets parsed by a different sub. All these subs are called from a general configuration parsing sub(&getconf). My problem is that the section-specific sub is the one that reads the header line for the next section and so the case statement in the parent sub never gets to read that input from the filehandle and can't figure out which sub to call to parse the next section of the file..
Simplified it looks like this:
Now my input files look like this:
My initial idea is to somehow put $_ back into the filehandle in the parse_section1() sub before returning so that the parent sub can read it itself. I could swear I saw that described somewhere but searching several perl resources (on|off)-line didn't lead anywhere. Is this something that can be done?
If not, does anyone see a perlish solution to this problem. I know I can check a variable in getconf or something and return the line from parse_section1() to that variable, but I was wondering if there is something a little less mundane out there.
Thanks in advance.
P.S. please excuse any minor syntax errors in my code, I wanted to trim it down to just the essentials to describe the problem I have.
Back to Seekers of Perl Wisdom