You are viewing a plain text version of this content. The canonical link for it is here.
Posted to asp@perl.apache.org by raptor <ra...@unacs.bg> on 2001/07/31 23:16:05 UTC

one more question

I'm doning something like this i.e. using include in many files :


myscript1.asp, myscript2.asp, myscript3.asp ... myscriptX.asp
================================================
<%
...code ...
<!--#include file=blah.inc-->
...code...
%>

currently I have have some vars that are used inside <included>-files but
has to declared into the outer script ( say myscript2.asp and
myscript4.asp), but on the other hand I don't need to define them in all
other scripts 'cause they don't use all of the functionality provided by
blah.inc ... and 'cause I'm under 'strict' I have to define  those virables
in all scripts but not only in the script where I need them...
One way to resolve this i've just tried (but has to go to bed :")) is to do
the following :

myscript2.asp, myscript4.asp
================================================
<%
...code ...
my $varThatINeedOnlyAtMyScript2 = 'xxx';

<!--#include file=blah.inc-->
...code...
%>

In all others I doesn't define this var but into blah.inc I put the
following :

blah.inc
========
use vars qw($varThatINeedOnlyAtMyScript2);
$varThatINeedOnlyAtMyScript2 = '' unless $varThatINeedOnlyAtMyScript2;

so now all scripts are happy :"), but this seems to me very ugly solution is
there something more elegant...
=====
iVAN
raptor@unacs.bg
=====



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


Re: one more question

Posted by Joshua Chamas <jo...@chamas.com>.
raptor wrote:
> 
> I'm doning something like this i.e. using include in many files :
> 
> myscript1.asp, myscript2.asp, myscript3.asp ... myscriptX.asp
> ================================================
> <%
> ...code ...
> <!--#include file=blah.inc-->
> ...code...
> %>
> 
> currently I have have some vars that are used inside <included>-files but
> has to declared into the outer script ( say myscript2.asp and
> myscript4.asp), but on the other hand I don't need to define them in all
> other scripts 'cause they don't use all of the functionality provided by
> blah.inc ... and 'cause I'm under 'strict' I have to define  those virables
> in all scripts but not only in the script where I need them...
> One way to resolve this i've just tried (but has to go to bed :")) is to do
> the following :
> 
> myscript2.asp, myscript4.asp
> ================================================
> <%
> ...code ...
> my $varThatINeedOnlyAtMyScript2 = 'xxx';
> 
> <!--#include file=blah.inc-->
> ...code...
> %>
> 

The way I like to do this is:

# global.asa
use Site;
use vars qw( $App ); # $App is global across scripts
sub Script_OnStart {
  $App = Site->new();  # returns bless hash ref
}

# myscript2.asp
$App->{varThatINeedOnlyAtMyScript2} = something;

# blah.inc
$App->{varThatINeedOnlyAtMyScript2}...

If you like method instead of member access, like:

$App->varThatINeedOnlyAtMyScript2()

then you might use something like Class::Struct to define
your Site $App object with.

another way is to pass arguments to the include that 
that include needs...

<% $Response->Include('blah.inc', $varThatINeedOnlyAtMyScript2) %>

then in blah.inc

<% my($varThatINeedOnlyAtMyScript2) = @_; %>

These approaches are not intuitive with ASP generally 
because they rely on extensions specific to Apache::ASP.

--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