Code Comments
Programming Forum and web based access to our favorite programming groups.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
Post Follow-up to this messageProbably 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 sy
min, 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>
>
>
Post Follow-up to this messageSean 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, sa y 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
Post Follow-up to this messageOn 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
Post Follow-up to this messageSean 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]
Post Follow-up to this messageIng. 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 :)
Post Follow-up to this messageMarek 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.]
Post Follow-up to this messageIng. 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, ca ll > 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.
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.