So, let's reverse this.
I have a module that will be used in perl.
I want all subs in the module to share the stagte of one variable...in my
case @context.
I also want any changes to @context to only effect the current user/request
under mod_perl.
What's the best approach?
1. declare
On Sat, 2005-08-20 at 15:17 -0400, Christopher H. Laco wrote:
> I do have a start_document sub, so if I always reset my @context = () in
> that, I should be fine.
This will only work if you do something like this:
my @context;
sub do_something {
push @context
}
sub reset_context {
On Sat, 2005-08-20 at 15:09 -0400, Christopher H. Laco wrote:
> I want all subs in the module to share the stagte of one variable...in
> my case @context.
>
> I also want any changes to @context to only effect the current
> user/request under mod_perl.
>
> What's the best approach?
Either pass
Christopher H. Laco wrote:
So, let's reverse this.
I have a module that will be used in perl.
I want all subs in the module to share the stagte of one variable...in
my case @context.
I also want any changes to @context to only effect the current
user/request under mod_perl.
What's the bes
Perrin Harkins wrote:
On Sat, 2005-08-20 at 19:44 +0200, Frank Maas wrote:
package A::B::C;
my %CFG = ( some_tag => some_config, ... }
...
sub do_something {
...
do_something_else( $CFG{some_tag} );
...
}
...
1;
After reading much of this discussion I am beginning to wonder if I am
creatin
Generally I make it a habit to pass the data explicitly:
package A::B::C;
my %CFG = ( some_tag => some_config, ... }
...
do_something( \%CFG );
sub do_something {
...
my $CFG = shift;
do_something_else( $CFG->{some_tag} );
...
}
...
1;
Boysenberry
boysenberrys.com |
On Sat, 2005-08-20 at 19:44 +0200, Frank Maas wrote:
> package A::B::C;
> my %CFG = ( some_tag => some_config, ... }
> ...
> sub do_something {
> ...
> do_something_else( $CFG{some_tag} );
> ...
> }
> ...
> 1;
>
> After reading much of this discussion I am beginning to wonder if I am
> crea
Guys,
I am getting a bit nervous and since it is Saturday and I am -1 day before
a deadline, this is not good. So, although this thread (and my question) is
drifting towards basic Perl, I try my luck.
I make use of the following construction
package A::B::C;
my %CFG = ( some_tag => some_config,
On Sat, 2005-08-20 at 12:55 -0400, Todd Finney wrote:
> This is probably just an issue of style, but avoiding stuff like this...
>
> our $x=10;
>
> 600 lines of code...
>
> sub foo {
> return $x++;
> }
> &foo();
>
> ...strikes me as common sense.
Sometimes you actually need a pers
Boysenberry Payne wrote:
If you worried about @context persisting my @context ought to keep it
local to the scope
@context is declared in unless you register it as a global while
manipulating it.
This is technically true, but confusing. Because the pushcontext() sub
below refers to a variabl
Christopher H. Laco wrote:
You're right. This got convoluted. Let's start over.
package MyApp;
my @context;
sub dosomething {
push @context, 'doingsomething';
};
1;
When this module is loaded into MP then given to each child process, for
each request the user makes to a page
Todd Finney wrote:
Perhaps I'm just underinformed, but using a variable in a subroutine
without declaring it or passing it in seems like asking for weird bugs.
Or asking for a persistent variable. Usually "our $color" is a bit
clearer for that though.
- Perrin
You're right. This got convoluted. Let's start over.
package MyApp;
my @context;
sub dosomething {
push @context, 'doingsomething';
};
1;
When this module is loaded into MP then given to each child process, for
each request the user makes to a page that calls dosomething(
I was just showing you an example to explain the scoping.
In a working situation it just depends on what you need @context for.
my @context allows you to declare @context local to where ever it's
declared. So:
my @context = qw( test1 );
{
@context = qw( test2 )
print @context
If you worried about @context persisting my @context ought to keep it
local to the scope
@context is declared in unless you register it as a global while
manipulating it. In other
words it should stay only as long as the scope it's declared in. So
that:
package MyMod1;
my @context = qw( test
On Sat, 2005-08-20 at 08:28 -0400, Christopher H. Laco wrote:
> Huh? Now I'm really confused. MyMod2 calls MyMod1::dosomething alters
> it's own @context (it should've been push @context, 'foo')...
>
> MyMod2 calls MyMod1::pushcontext('anotherfoo') to also alter MyMod1s
> @context.
I've lost tr
Perrin Harkins wrote:
On Fri, 2005-08-19 at 20:55 -0400, Christopher H. Laco wrote:
So, changing to
package MyMod;
my @context;
sub dosomething {
push @context;
#...do other stuff..
};
sub pushcontext {
push @context, shift;
};
1;
Woudld fix the persistance is
On Fri, 2005-08-19 at 20:55 -0400, Christopher H. Laco wrote:
> So, changing to
>
> package MyMod;
>
> my @context;
> sub dosomething {
> push @context;
> #...do other stuff..
> };
> sub pushcontext {
> push @context, shift;
> };
>
> 1;
>
>
> Woudld fix th
On Fri, 2005-08-19 at 21:23 -0400, Christopher H. Laco wrote:
> Ah does that closure become a global?
>
> package MyApp;
> {
>
> };
>
>
> &MyApp::__ANON__ (ish)?
Not exactly, but it does persist the value of @context. That's what
closures do.
> Makes sense now that I think about it.
> So
Perrin Harkins wrote:
On Fri, 2005-08-19 at 20:24 -0400, Christopher H. Laco wrote:
I'm assuming that each tome dosomething() changes @contect, it's only
changing @contect for that MP child process.
Correct. However, dosomething() is a closure in your code, so @context
will persist.
Ah...
Perrin Harkins wrote:
On Fri, 2005-08-19 at 20:24 -0400, Christopher H. Laco wrote:
I'm assuming that each tome dosomething() changes @contect, it's only
changing @contect for that MP child process.
Correct. However, dosomething() is a closure in your code, so @context
will persist.
So,
On Fri, 2005-08-19 at 20:24 -0400, Christopher H. Laco wrote:
> I'm assuming that each tome dosomething() changes @contect, it's only
> changing @contect for that MP child process.
Correct. However, dosomething() is a closure in your code, so @context
will persist.
> Now, I need to have another
22 matches
Mail list logo