For Programmers: Free Programming Magazines  


Home > Archive > PERL CGI Beginners > November 2004 > output buffering









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author output buffering
Ing. Branislav Gerzo

2004-11-29, 8:55 pm

hi all,

is there any possibility, how to easy and fast install some script,
which changes perl script output ? For cleaner explanation:

I want do script which takes *any* (perl,cgi site) output, parse it for
mails (2g@2g.us) and all occurencies changes to [2g]-at-[2g]_us
for example. I look into php, and they call such a functions as
"Output Buffering Functions"

thanks


-=x=-
Skontrolované antivírovým programom NOD32

Sean Davis

2004-11-29, 8:55 pm

Probably the simplest way is to save all your output into a variable, say
$html, rather than printing directly, as you would typically. Then, make a
simple function that displays $html and performs any filtering you like.
Such a subroutine might look like:

#somewhere in the code....
my $html='';
$html='hello world';
filter_and_output($html);

#and the output subroutine....
sub filter_and_output {
my $html=shift;
#in a CGI environment, put header, start_html, etc. here.
$html=~ s/@/at/g;
print $html;
#and in CGI, put end_html, etc. here. You could also put a "footer"
with email for symin, etc. here.
}

Mind that this is untested!
----- Original Message -----
From: "Ing. Branislav Gerzo" <konfera@2ge.us>
To: <beginners-cgi@perl.org>
Sent: Monday, November 29, 2004 4:46 PM
Subject: output buffering


> hi all,
>
> is there any possibility, how to easy and fast install some script,
> which changes perl script output ? For cleaner explanation:
>
> I want do script which takes *any* (perl,cgi site) output, parse it for
> mails (2g@2g.us) and all occurencies changes to [2g]-at-[2g]_us
> for example. I look into php, and they call such a functions as
> "Output Buffering Functions"
>
> thanks
>
>
> -=x=-
> Skontrolovane antivirovym programom NOD32
>
>
> --
> To unsubscribe, e-mail: beginners-cgi-unsubscribe@perl.org
> For additional commands, e-mail: beginners-cgi-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>



Ing. Branislav Gerzo

2004-11-30, 3:55 am

Sean Davis [SD], on Monday, November 29, 2004 at 17:45 (-0500) has on
mind:

SD> Probably the simplest way is to save all your output into a variable, say
SD> $html, rather than printing directly, as you would typically. Then, make a
SD> simple function that displays $html and performs any filtering you like.
SD> Such a subroutine might look like:

yes, I thought about this, I am just curious, if exist any other way.
This is ofcourse easy, but what about with really complex CGI sites ?

SD> Mind that this is untested!

that's not a problem :)

--

...m8s, cu l8r, Brano.

[When taglines are outlawed, only moderators will have tag]



-=x=-
Skontrolované antivírovým programom NOD32

Sean Davis

2004-11-30, 8:55 am


On Nov 30, 2004, at 1:42 AM, Ing. Branislav Gerzo wrote:

> Sean Davis [SD], on Monday, November 29, 2004 at 17:45 (-0500) has on
> mind:
>
> SD> Probably the simplest way is to save all your output into a
> variable, say
> SD> $html, rather than printing directly, as you would typically.
> Then, make a
> SD> simple function that displays $html and performs any filtering you
> like.
> SD> Such a subroutine might look like:
>
> yes, I thought about this, I am just curious, if exist any other way.
> This is ofcourse easy, but what about with really complex CGI sites ?
>


Perhaps you should tell us exactly what you want to do. For CGI, many
cgi application environments build in a post-processing hook that is
called right before the HTML is dumped to the browser. However, one
still has to build this hook, and a VERY simplified version is what I
sent earlier. Perhaps you need to let us know what your exact needs
are and what constraints you must work within so that we can be more
specific?

Sean

Ing. Branislav Gerzo

2004-11-30, 8:55 am

Sean Davis [SD], on Tuesday, November 30, 2004 at 05:55 (-0500) typed:

SD> Perhaps you should tell us exactly what you want to do. For CGI, many
SD> cgi application environments build in a post-processing hook that is
SD> called right before the HTML is dumped to the browser. However, one
SD> still has to build this hook, and a VERY simplified version is what I
SD> sent earlier. Perhaps you need to let us know what your exact needs
SD> are and what constraints you must work within so that we can be more
SD> specific?

Ok, imagine I want give out free, simple script for CGI websites,
which I wrote (changes every mail...). I am interesting about, how
I can spread this script, so people can import it without any
problems, or high knowledge. That's all.

--

...m8s, cu l8r, Brano.

[Computer User Group - Nerd Heard]


Marek Kilimajer

2004-11-30, 3:55 pm

Ing. Branislav Gerzo wrote:
> hi all,
>
> is there any possibility, how to easy and fast install some script,
> which changes perl script output ? For cleaner explanation:
>
> I want do script which takes *any* (perl,cgi site) output, parse it for
> mails (2g@2g.us) and all occurencies changes to [2g]-at-[2g]_us
> for example. I look into php, and they call such a functions as
> "Output Buffering Functions"
>


Just my idea, not sure if it will work: use urlrewriting to catch all
requests with one script, in that script read the original request, call
it and catch it's output. hope you understand me :)
Ing. Branislav Gerzo

2004-11-30, 3:55 pm

Marek Kilimajer [MK], on Tuesday, November 30, 2004 at 15:59 (+0100)
wrote:

MK> Just my idea, not sure if it will work: use urlrewriting to catch all
MK> requests with one script, in that script read the original request, call
MK> it and catch it's output. hope you understand me :)

no, I don't. Which original request ? You are talking about apache ?

--

...m8s, cu l8r, Brano.

[You had to give up. I'm too dangerous for you.]


Marek Kilimajer

2004-11-30, 3:55 pm

Ing. Branislav Gerzo wrote:
> Marek Kilimajer [MK], on Tuesday, November 30, 2004 at 15:59 (+0100)
> wrote:
>
> MK> Just my idea, not sure if it will work: use urlrewriting to catch all
> MK> requests with one script, in that script read the original request, call
> MK> it and catch it's output. hope you understand me :)
>
> no, I don't. Which original request ? You are talking about apache ?
>


User requests /cgi-bin/script.pl

De to the rewrite rule (yes, apache) will execute
/cgi-bin/rewrite_emails.pl instead.

In rewrite_emails.pl you wil find out what is the original request, it
should be available in some env variable I don't remember. It's
/cgi-bin/script.pl in this case

Then you open a connection to the localhost, repeat the request with the
same headers, read in the responce and do whatever transformation you
need. Or you can do a subrequest, I think it's posible in perl.

This is just an idea. I'm not fluent in perl, I do php. The difficult
part is the rewrite rule, you have to be carefull not to make an
infinite loop - request from rewrite_emails.pl must not be rewritten
again to /cgi-bin/rewrite_emails.pl. You can filter by IP address,
subrequest, maybe other options.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com