From: Paul W. <pg...@va...> - 2002-11-27 14:02:28
|
Why would you put the array in a session? Then you're storing it in the database for each session. I don't understand why you say that an array initialized as the original poster said: @global_array = (1,2,3); ( I'd add an 'our' to satisfy use strict qw(vars): ) our @global_array = (1,2,3); needs to referenced with a wrapping function. It will simply be accessible from everywhere in the MyModel.pm module. While it is true that you can't guarantee that subsequent requests will be served by the same Apache process, do certainly do know that all requests will be served by a process that has used the module, and hence initialized the array. What is the difficulty here? -Paul > -----Original Message----- > From: pag...@li... > [mailto:pag...@li...] On Behalf > Of Bill Karwin > Sent: Tuesday, November 26, 2002 5:18 PM > To: pag...@li... > Subject: Re: [Pagekit-users] Global vars > > > At 02:31 PM 11/26/2002 +0500, you wrote: > >I need global array, wich would be accessible from everywhere in my > >MyModel.pm (by $model, f.e.) > >So, in MyModel i add before all subs: > > @global_arr = (1,2,3); > > I think you'd need to access that array in the following way: > sub subrut { > my @local_arr = @MyModel::global_arr; > } > > But be careful about using global arrays, since they are not > global to all > Apache processes. You can't rely on the array being in the > same state > between requests, because you can't guarantee that subsequent > requests in a > session will be served by the same Apache process. Unless > you use the > array as read-only, and never modify it in any session, after it is > initialized. > > So in the general case, I'd recommend putting the global > array into your > model's session object instead of in a global variable. > > That is, in pkit_common_code(): > $model->session->{global_arr_ref} = [ 1, 2, 3 ] unless > ($model->session->{global_arr_ref}); > > Then in your model handlers: > my @local_arr = @{$model->session->{global_arr_ref}}; > > Regards, > Bill Karwin > > > > ------------------------------------------------------- > This SF.net email is sponsored by: Get the new Palm Tungsten T > handheld. Power & Color in a compact size! > http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0002en > _______________________________________________ > Pagekit-users mailing list > Pag...@li... > https://lists.sourceforge.net/lists/listinfo/pagekit-users > |