Do you know where your variables are? | |
PerlMonks |
Formats and Variable Scopeby Tanalis (Curate) |
on Nov 19, 2002 at 10:26 UTC ( [id://214068]=perlquestion: print w/replies, xml ) | Need Help?? |
Tanalis has asked for the wisdom of the Perl Monks concerning the following question:
Heys,
I'm currently working on a large project, part of which involves converting a large number of reports to use database data and formats. I'm getting the data from the DB happily enough, and have defined a set of formats which I've put into a module of their own to try and keep the code readable and maintainable (the current reporting scripts are neither). The script compiles happily with the format module included, but when it comes to outputting the data I simply get the format itself and pages full of blank lines, as if the write is happening but there's no data in the variables. I've consulted the Camel (2nd Ed.), which says that variables must be in scope when the format is defined in order to be used in that format. I'm ensuring this is happening (I think) by having each set of formats in a subroutine (in the module), which I call just prior to the first write to carry out the format definition. I'm guessing that this has something to do with variable scope, but I can't seem to find a way to solve the problem or work round it. If anyone has any comments or ideas, they'd be welcomed. Example code is below.
--Foxcub
Back to
Seekers of Perl Wisdom
|
|