Loading ...
Sorry, an error occurred while loading the content.

XML - problem with variable scoping

Expand Messages
  • luciflatum
    Hi all! I am using the XML engine to embed dynamic content into an HTML page via Apache::ASP. What I need is a simple way to retain the values of the variables
    Message 1 of 5 , Nov 2, 2003
    • 0 Attachment
      Hi all!
      I am using the XML engine to embed dynamic content into an HTML page
      via Apache::ASP. What I need is a simple way to retain the values of
      the variables between different XML tags within the same page.

      Something like this:

      ---TOP OF PAGE---
      <my:load_all/>

      <my:display variable="loaded1"/>

      <my:unload_all/>
      ---END OF PAGE---

      This layout triggers a problem: if I use the strict pragma I can't use
      the same variables (each my:: function is isolated in scope); if I
      declare a global variable in my::load_all there are all the usual
      conflicts between different sessions.

      Does anybody know how to fix this?

      TIA


      ---------------------------------------------------------------------
      To unsubscribe, e-mail: asp-unsubscribe@...
      For additional commands, e-mail: asp-help@...
    • Helmut
      Hi TIA, you could use a unique package name (as Apache::ASP does it with global variables without explizit package name - i think), for example some kind of
      Message 2 of 5 , Nov 2, 2003
      • 0 Attachment
        Hi TIA,

        you could use a unique package name (as Apache::ASP does it with global
        variables without explizit package name - i think), for example some kind
        of time-information merged into the package name.

        But i think the easiest way would be the usage of session variables:

        sub my::load_all
        { [..]
        $Session->{'loaded1'} = "somevalue";
        [..]
        }

        [..]
        <my:display variable1=<%=$Session->{'loaded1'}%>/>
        [..]

        sub my::unload_all
        { [..]
        delete $Session->{'loaded1'};
        [..]

        Of course you have to activate Sessions to use this.

        Helmut

        --On Sunday, November 02, 2003 19:30:52 +0000 luciflatum
        <llucif@...> wrote:

        > Hi all!
        > I am using the XML engine to embed dynamic content into an HTML page
        > via Apache::ASP. What I need is a simple way to retain the values of
        > the variables between different XML tags within the same page.
        >
        > Something like this:
        >
        > ---TOP OF PAGE---
        > <my:load_all/>
        >
        > <my:display variable="loaded1"/>
        >
        > <my:unload_all/>
        > ---END OF PAGE---
        >
        > This layout triggers a problem: if I use the strict pragma I can't use
        > the same variables (each my:: function is isolated in scope); if I
        > declare a global variable in my::load_all there are all the usual
        > conflicts between different sessions.
        >
        > Does anybody know how to fix this?
        >
        > TIA
        >
        >
        > ---------------------------------------------------------------------
        > To unsubscribe, e-mail: asp-unsubscribe@...
        > For additional commands, e-mail: asp-help@...
        >





        ---------------------------------------------------------------------
        To unsubscribe, e-mail: asp-unsubscribe@...
        For additional commands, e-mail: asp-help@...
      • Helmut
        Hi TIA, correction: or seem not to work, because ASP does
        Message 3 of 5 , Nov 2, 2003
        • 0 Attachment
          Hi TIA,

          correction:

          <my:display variable="$Session->{'loaded1'}"/> or
          <my:display variable="<%=$Session->{'loaded1'}%>"/>

          seem not to work, because ASP does not recognize it as variables.
          You could use

          <% my $loaded1 = $Session->{'loaded1'}; %>
          <my:display variable="$loaded1"/>

          but this would be the same, as if you would use

          [..]
          my $loaded1;

          sub my::load_all
          { [..]
          $loaded1 = 'something';
          [..]
          }
          [..]

          without any session variables.
          This works for me, even with "UseStrict 1".
          But, of course, you must declare $loaded1 OUTSIDE the subroutines.


          Helmut


          --On Sunday, November 02, 2003 19:30:52 +0000 luciflatum
          <llucif@...> wrote:

          > Hi all!
          > I am using the XML engine to embed dynamic content into an HTML page
          > via Apache::ASP. What I need is a simple way to retain the values of
          > the variables between different XML tags within the same page.
          >
          > Something like this:
          >
          > ---TOP OF PAGE---
          > <my:load_all/>
          >
          > <my:display variable="loaded1"/>
          >
          > <my:unload_all/>
          > ---END OF PAGE---
          >
          > This layout triggers a problem: if I use the strict pragma I can't use
          > the same variables (each my:: function is isolated in scope); if I
          > declare a global variable in my::load_all there are all the usual
          > conflicts between different sessions.
          >
          > Does anybody know how to fix this?
          >
          > TIA
          >
          >
          > ---------------------------------------------------------------------
          > To unsubscribe, e-mail: asp-unsubscribe@...
          > For additional commands, e-mail: asp-help@...
          >





          ---------------------------------------------------------------------
          To unsubscribe, e-mail: asp-unsubscribe@...
          For additional commands, e-mail: asp-help@...
        • Josh Chamas
          ... As of v2.45, can work with the XMLSubsPerlArgs setting set to Off. This will become the default one
          Message 4 of 5 , Nov 3, 2003
          • 0 Attachment
            Helmut wrote:
            > Hi TIA,
            >
            > correction:
            >
            > <my:display variable="$Session->{'loaded1'}"/> or
            > <my:display variable="<%=$Session->{'loaded1'}%>"/>
            >
            > seem not to work, because ASP does not recognize it as variables.
            > You could use

            As of v2.45, <my:display variable="<%=$Session->{'loaded1'}%>"/>
            can work with the XMLSubsPerlArgs setting set to Off. This will
            become the default one day...

            http://www.apache-asp.org/config.html#XMLSubsPerlA21dba3d7

            Per the original request, I believe it can be neatly handled
            instead of using $Session, the developer sets up their own $Data
            global that they clear in Script_OnStart for per request data passing.
            Use of $Session can be expensive compared to an in memory hash,
            so should only be reserved for use when needing to pass data between
            requests for a user.

            Regards,

            Josh
            ________________________________________________________________
            Josh Chamas, Founder phone:925-552-0128
            Chamas Enterprises Inc. http://www.chamas.com
            NodeWorks Link Checker http://www.nodeworks.com


            ---------------------------------------------------------------------
            To unsubscribe, e-mail: asp-unsubscribe@...
            For additional commands, e-mail: asp-help@...
          • Fagyal, Csongor
            ... ...and that day we can start calling it Apache::JSP :-))) - Csongor ... To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org For additional commands,
            Message 5 of 5 , Nov 3, 2003
            • 0 Attachment
              > As of v2.45, <my:display variable="<%=$Session->{'loaded1'}%>"/>
              > can work with the XMLSubsPerlArgs setting set to Off. This will
              > become the default one day...

              ...and that day we can start calling it Apache::JSP :-)))

              - Csongor


              ---------------------------------------------------------------------
              To unsubscribe, e-mail: asp-unsubscribe@...
              For additional commands, e-mail: asp-help@...
            Your message has been successfully submitted and would be delivered to recipients shortly.