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.


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
Domain Nodelet?
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 imbibing at the Monastery: (5)
As of 2023-02-01 12:49 GMT
Find Nodes?
    Voting Booth?
    I prefer not to run the latest version of Perl because:

    Results (2 votes). Check out past polls.