Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Formats and Variable Scope

by jreades (Friar)
on Nov 19, 2002 at 12:07 UTC ( #214088=note: print w/ replies, xml ) Need Help??

in reply to Formats and Variable Scope

I may be misreading the code, but it looks like you're trying to access the formats as if they were variables declared in your imported package, when they're actually being defined within a sub.

You have two choices, depending on how you want to define your formats:

  1. Define the format(s) outside of the sub
  2. Have the sub return the two formats

I'd probably go with '1' since there's nothing really happening that seems to require a sub.

package Formatting::Admin::Usage; format top = ... format data = ... package main; $^ = Formatting::Admin::Usage::top; $~ = Formatting::Admin::Usage::data;

I haven't tried compiling this and it's been a long time since I've worked with formats, so you might need to do some tweaks (I notice that in your code the last two lines use double-quotes to make the assignment, for instance), but this gives you a fairly flexible structure... have more Admin reports? Define a new package Formatting::Admin::Other::top. Want to have user reports? Formatting::User::Usage::top. And so on.


Comment on Re: Formats and Variable Scope
Download Code
Replies are listed 'Best First'.
Re: Re: Formats and Variable Scope
by Tanalis (Curate) on Nov 19, 2002 at 12:29 UTC
    The sub was there simply because I understood that the variables had to be in scope when the format was defined - calling the sub allowed me to choose when to define it.

    I do like the idea for the structure, though .. that works very well in the environment here.

    Still, the variable issue is still there, with or without the sub, and regardless of the structure of the modules.

    Thanks, though, you've given me some ideas to experiment with.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://214088]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2015-11-27 00:57 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (710 votes), past polls