Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
The stupid question is the question not asked
 
PerlMonks  

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.

HTH


Comment on Re: Formats and Variable Scope
Download Code
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.

    --Foxcub

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (11)
As of 2014-04-18 14:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (469 votes), past polls