First, you'll need a little background. I'm working on a template system (yes, I know there are modules out there, but I'm trying to learn how to do it in this manner first). Basically, I have an HTML document which contains HTML REM tags like this: <!-- fillin(getLogo) --> (this is the same template system I asked another qeustion about a couple of weeks ago, so the background info may sound familiar). Basically, whatever is within the parens within the fillin statement is a subroutine that gets called. Actually, it's just a variable that gets compared to a list of allowable subroutine calls (I do this for security). The point is that the REM tag gets replaced with the HTML that is generated from whatever subroutine is called. All this is compiled into a buffer which is then printed at the end.

Now, in some situations, I would like to manipulate header information. I can generate the header separately, but I would like to manipulate it from some of these subroutines. Specifically, I'd like to create a refresh meta tag, and I would like to have cookie information set by some of these subroutines. The problem is that I cannot seem to figure out how to return anything other than the following code snippet (I will explain variables after the code -- the program is way too large to paste here):

open(FILE, "<$template") or die "Template : Couldn't open $template : +$!\n"; while (<FILE>) { $HTML .= $_ } close(FILE); while ($HTML =~ /<!-- fillin\((.+?)\) -->/) { my $command_output = &{$templateCall->{$1}}; # a subroutine call $HTML =~ s/<!-- fillin\(.+?\) -->/$command_output/; }

Let me explain some of the variables:
$template is pulled from the user database. A user can change themes within this system, and therefore has a variable set within the database for this. There is no user input from the URL.
$HTML is pre-defined within this subroutine (local variable). This is basically the entire output which will be filtered.
$templateCall is a hash-reference that basically lists the subroutines associated with the template's fillin() commands. Again, I do this for security.

Now, assuming that I call a subroutine that checks a user's username and password, then logs them in, I want to be able to return cookie information (or refresh information) back to this subroutine so that I can run further tests. I basically want to add a line for a cookie if a cookie variable is defined. And I want to be able to add a meta tag to my header if said variable is defined. I modified the code to the following, and it doesn't really seem to work (assume that I do define all these variables):

while ($HTML =~ /<!-- fillin\((.+?)\) -->/) { my $command_output = &{$templateCall->{$1}}; # a subroutine call ($HTML, $cookie, $refresh) =~ s/<!-- fillin\(.+?\) -->/$command_outp +ut/; }

From the subroutine, I always return data to $HTML. Whether or not I return data to $cookie and $refresh or not depends on the nature of the subroutine. I think I know why it's not working (the tilde), but I can't seem to figure out a way around that.

I have no problem generating header information after this point, and just making sure that it prints the header first.

Any help would be appreciated.

--Coplan


In reply to Header data from arbitrary calls by Coplan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.