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.

# module Formats.pm use strict; package Formats; sub admin_usage_reports { format admin_usage_top = A D M I N U S A G E Date: @<<<<<<<<<< $report_date Username Login Logout Activity ---------------------------------------------------------- . format admin_usage_data = @<<<<<<< @<<<<<<< @<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<< $usr, $login, $logout, $activity . } # main script Formats::admin_usage_reports; $^ = "Formats::admin_usage_top"; $~ = "Formats::admin_usage_data"; write;

--Foxcub


In reply to Formats and Variable Scope by Tanalis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.