You are viewing a plain text version of this content. The canonical link for it is here.
Posted to asp@perl.apache.org by Joshua Chamas <jo...@chamas.com> on 2001/11/12 20:30:38 UTC

Re: how to access vars of global.asa from my.asp file

> SubbaReddy M wrote:
> 
> Hello Gurus,
> 
> How to access a scalar variable in *.asp file, which declared in global.asa file?
> Though it is declared as use vars($title) in global.asa, unable access the $title variable in *.asp file.
> 

# in global.asa
my $Var = "first project";

# in script
<% print $Var; %>

Scripts are compiled into the same package as the global.asa, which is why 
you can share variables in this way.

> So, I tried to put in $Application{'title'} = "This is my 1st Apache::ASP project"; in global.asa
> and tried to print in *.asp file.

This should have been an error.  Remember to configure "PerlSetVar UseStrict 1",
which should have reported this as an error if configured.  The reason
is that %Application is not defined, which $Application{'title'} would
reference.  Rather $Application should be defined, so you could do
$Application->{title} = "This is my 1st...";

This should work.  But generally, unless you have a very good reason
for using $Application, don't!  It can be a big performance drag
on a site if not used carefully.  Things in $Application can often
by defined as globals in Script_OnStart, or in the global.asa file
as above like $Var.

# global.asa
use vars qw( %Strings ); # declare globals

%Strings = (
	'error' => 'This is an error',
	'greeting' => 'This is a greeting.'
	);

# then in ASP script
<%= $Strings{'error'} %>

> I have declared variable $title in global.asa
> and when I tried to access http://192.168.1.235/aps/1.asp
> 
> I am getting error page.
> 

What's the error page?

> 
> >>>>>>>>>> global.asa    >>>>>>>>>>>
> $MLDBM::RemoveTaint = 1;
> use vars qw($title);
> 

If you want to init $title on a per script request, then 
you probably want to set it to something either in your script like
  <% $title = "something"; %>

or in global.asa Script_OnStart

sub Script_OnStart {
  $title = "title here";
}

> sub Application_OnStart {
>         $Response->AppendToLog("Application_OnStart! global.asa");
>         $Application->{Count} = 20;
>         $title = "FrontlineSoft limited";
> }
> 

Not in Application_OnStart though.  Application_OnStart gets fired
only when your web site is starting up when the first user visits
it, and is thus not very useful.

-- Josh
_________________________________________________________________
Joshua Chamas                           Chamas Enterprises Inc.
NodeWorks Founder                       Huntington Beach, CA  USA 
http://www.nodeworks.com                1-714-625-4051

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


Re: how to access vars of global.asa from my.asp file

Posted by Joshua Chamas <jo...@chamas.com>.
>From the look of it your global.asa is not getting loaded.
Make sure that Global is pointed to the directory that your
global.asa is in.  If you have a .htaccess file being loaded,
make sure to set Global correctly there.

You can try to see if your global.asa is being loaded, by
doing something like:

# global.asa
print STDERR "!!! global.asa loading !!!\n";

sub Script_OnStart {
  $Response->AppendToLog("global.asa loaded !!!");
}

Then check out your error log, if these things didn't show
up, your Global is likely not set right.  If you would like
to see what Apache::ASP thinks your Global is configured as,
try setting Debug -1, then look in the error_log, and see
what the value of global is for the ASP object when its
getting destroyed.

--Josh

SubbaReddy M wrote:
> 
> Dear Joshua,
> 
> > > How to access a scalar variable in *.asp file, which declared in
> global.asa file?
> > > Though it is declared as use vars($title) in global.asa, unable access
> the $title variable in *.asp file.
> > >
> >
> > # in global.asa
> > my $Var = "first project";
> >
> > # in script
> > <% print $Var; %>
> 
>            As you said,
>                     I  placed the my $Var = "first project"; in global.asa
>                     and tried to print from 1.asp file by using <% print
> $Var;%>
>           but it's giving 500: Internal Server Error page.
>            So checked the my error_log file : that is
>             [root@qclinux asp]# tail /var/log/httpd/error_log
> >>>>>>>>>>>>>>>>>>>> error log >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.
>             [Tue Nov 13 05:47:36 2001] [error] [asp] [1503] [error] Global
> symbol "$Var" requires explicit package name at 1.asp line 17. <--> BEGIN
> not safe after errors--compilation aborted at 1.asp line 20. <--> ,
> /usr/lib/perl5/site_perl/5.6.1/Apache/ASP.pm line 2089
> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> 
> >
> > # global.asa
> > use vars qw( %Strings ); # declare globals
> >
> > %Strings = (
> > 'error' => 'This is an error',
> > 'greeting' => 'This is a greeting.'
> > );
> >
> > # then in ASP script
> > <%= $Strings{'error'} %>
> 
>              So, I tried for global declaration, as you suggested
>               but it also raising the same error: 500: Internal Server Error
> 
> >>>>>>>>>>>>>> error log >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> [root@qclinux asp]#tail /var/log/httpd/error_log
> 
> [Tue Nov 13 06:08:23 2001] [error] [asp] [1570] [error] Global symbol
> "%Strings" requires explicit package name at 1.asp line 19. <--> BEGIN not
> safe after errors--compilation aborted at 1.asp line 22. <--> ,
> /usr/lib/perl5/site_perl/5.6.1/Apache/ASP.pm line 2089
> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> 
> >
> > Scripts are compiled into the same package as the global.asa, which is why
> > you can share variables in this way.
> >
> > > So, I tried to put in $Application{'title'} = "This is my 1st
> Apache::ASP project"; in global.asa
> > > and tried to print in *.asp file.
> >
> > This should have been an error.  Remember to configure "PerlSetVar
> UseStrict 1",
> 
>     Yes, it has given error on trying access the $Application{'title'} in
> 1.asp file.
>     because of I have "PerlSetVar UseStrict 1" in httpd.conf
>     and $Application{title} = "some thing"; is placed in sub Script_OnStart
> (global.asa)
>     and tried to print in 1.asp
>     <%=$Application->{title}%>
> and
>     <% print $Application->{title}%>
> 
> But, it is printing blank and not raising any error.
> 
> Please, how to get it done?
> I want $Var as global and $Application->{title} on Script_OnStart .
> 
> I will be waiting for your reply.
>

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


Re: how to access vars of global.asa from my.asp file

Posted by Joshua Chamas <jo...@chamas.com>.
"John D. Leonard II" wrote:
> 
> All:
> 
> I noticed two diffent syntaxes in the previous thread:
> 
> > > # global.asa
> > > my $Var = "first project";
> 
> and
> 
> > > # global.asa
> > > use vars qw( $Var ); # declare globals
> > > $Var = "first project";
> 
> What's the difference?  Which is preferred?
> 

The my() scoping of package global's can be a little complex
so I would stay away from it generally.  A my() scoped
package global is supposed to be invisible from outside the 
package, so is something like a static global in C if my memory 
serves me. ( It almost 4AM, so have little memory now :)
Further, if a my() scoped global is moved to a sub, its no
longer a private package global, its locally scoped in the sub.

So, for globals I would stick with globals, with the use vars qw()
declaration syntax generally, unless you explicitly want to 
privatize something.

--Josh

_________________________________________________________________
Joshua Chamas                           Chamas Enterprises Inc.
NodeWorks Founder                       Huntington Beach, CA  USA 
http://www.nodeworks.com                1-714-625-4051

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


RE: how to access vars of global.asa from my.asp file

Posted by "John D. Leonard II" <jo...@ce.gatech.edu>.
All:

I noticed two diffent syntaxes in the previous thread:

> > # global.asa
> > my $Var = "first project";

and

> > # global.asa
> > use vars qw( $Var ); # declare globals
> > $Var = "first project";

What's the difference?  Which is preferred?

JL

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


Re: how to access vars of global.asa from my.asp file

Posted by SubbaReddy M <m_...@hotmail.com>.
Dear Joshua,

> > How to access a scalar variable in *.asp file, which declared in
global.asa file?
> > Though it is declared as use vars($title) in global.asa, unable access
the $title variable in *.asp file.
> >
>
> # in global.asa
> my $Var = "first project";
>
> # in script
> <% print $Var; %>

           As you said,
                    I  placed the my $Var = "first project"; in global.asa
                    and tried to print from 1.asp file by using <% print
$Var;%>
          but it's giving 500: Internal Server Error page.
           So checked the my error_log file : that is
            [root@qclinux asp]# tail /var/log/httpd/error_log
>>>>>>>>>>>>>>>>>>>> error log >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.
            [Tue Nov 13 05:47:36 2001] [error] [asp] [1503] [error] Global
symbol "$Var" requires explicit package name at 1.asp line 17. <--> BEGIN
not safe after errors--compilation aborted at 1.asp line 20. <--> ,
/usr/lib/perl5/site_perl/5.6.1/Apache/ASP.pm line 2089
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

>
> # global.asa
> use vars qw( %Strings ); # declare globals
>
> %Strings = (
> 'error' => 'This is an error',
> 'greeting' => 'This is a greeting.'
> );
>
> # then in ASP script
> <%= $Strings{'error'} %>

             So, I tried for global declaration, as you suggested
              but it also raising the same error: 500: Internal Server Error

>>>>>>>>>>>>>> error log >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
[root@qclinux asp]#tail /var/log/httpd/error_log

[Tue Nov 13 06:08:23 2001] [error] [asp] [1570] [error] Global symbol
"%Strings" requires explicit package name at 1.asp line 19. <--> BEGIN not
safe after errors--compilation aborted at 1.asp line 22. <--> ,
/usr/lib/perl5/site_perl/5.6.1/Apache/ASP.pm line 2089
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>



>
> Scripts are compiled into the same package as the global.asa, which is why
> you can share variables in this way.
>
> > So, I tried to put in $Application{'title'} = "This is my 1st
Apache::ASP project"; in global.asa
> > and tried to print in *.asp file.
>
> This should have been an error.  Remember to configure "PerlSetVar
UseStrict 1",

    Yes, it has given error on trying access the $Application{'title'} in
1.asp file.
    because of I have "PerlSetVar UseStrict 1" in httpd.conf
    and $Application{title} = "some thing"; is placed in sub Script_OnStart
(global.asa)
    and tried to print in 1.asp
    <%=$Application->{title}%>
and
    <% print $Application->{title}%>

But, it is printing blank and not raising any error.


Please, how to get it done?
I want $Var as global and $Application->{title} on Script_OnStart .

I will be waiting for your reply.

Thank you,

-SubbaReddy


---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org