Piping output to and from external perl routine

2004-10-15 Thread Dan Fish
Is there an easy way to pipe output to an external perl routine and then
pipe the output of that routine back in for more processing?

In particular I want to use LWP::UserAgent to grab a web page, pipe the
output to Tom Christiansen's "striphtml" routine
(http://www.cpan.org/authors/Tom_Christiansen/scripts/striphtml.gz) and then
pipe that output back in for some subsequent processing.  Something like:

my $ua = new LWP::UserAgent;
my $request = new HTTP::Request('GET', $myURL);
my $response = $ua->request($request);
my $page = $response->content;

open(STRIPHTML, "|striphtml.pl") || die("Can\'t open striphtml: $!\n");
print STRIPHTML $page;
close(STRIPHTML); # maybe not such a good idea?

This works fine so far... But now what?  How do I get the output of
striphtml.pl back in to do some more processing on it?

I know I can do this with a temporary file, but I loathe using them when
reasonable alternatives might be available...

Thanks!
-Dan

---
Dan Fish - [EMAIL PROTECTED] 
"A -good- dive buddy will be there if you run out of air, a -great- one will
be there before you run out!"


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Piping output to and from external perl routine

2004-10-15 Thread Wiggins d Anconia
> Is there an easy way to pipe output to an external perl routine and then
> pipe the output of that routine back in for more processing?
> 
> In particular I want to use LWP::UserAgent to grab a web page, pipe the
> output to Tom Christiansen's "striphtml" routine
> (http://www.cpan.org/authors/Tom_Christiansen/scripts/striphtml.gz)
and then
> pipe that output back in for some subsequent processing.  Something like:
> 
> my $ua = new LWP::UserAgent;
> my $request = new HTTP::Request('GET', $myURL);
> my $response = $ua->request($request);
> my $page = $response->content;
> 
> open(STRIPHTML, "|striphtml.pl") || die("Can\'t open striphtml: $!\n");
> print STRIPHTML $page;
> close(STRIPHTML); # maybe not such a good idea?
> 
> This works fine so far... But now what?  How do I get the output of
> striphtml.pl back in to do some more processing on it?
> 
> I know I can do this with a temporary file, but I loathe using them when
> reasonable alternatives might be available...
> 
> Thanks!
> -Dan
>

Check out IPC::Open3 and IPC::Open2,

perldoc IPC::Open3
perldoc perlopentut

Haven't looked at striphtml but I suspect this could be done with a
module inside of the main source rather than shelling out to another
program. Or by pulling in the program as a lib and calling its code
directly??

http://danconia.org
 
> ---
> Dan Fish - [EMAIL PROTECTED] 
> "A -good- dive buddy will be there if you run out of air, a -great-
one will
> be there before you run out!"
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
> 
> 
> 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Piping output to and from external perl routine

2004-10-15 Thread Gunnar Hjalmarsson
Dan Fish wrote:
Is there an easy way to pipe output to an external perl routine and
then pipe the output of that routine back in for more processing?
It depends on what the external Perl routine does.
In particular I want to use LWP::UserAgent to grab a web page, pipe
the output to Tom Christiansen's "striphtml" routine
(http://www.cpan.org/authors/Tom_Christiansen/scripts/striphtml.gz)
and then pipe that output back in for some subsequent processing.
The striphtml program only consists of a few substitutions, so you
need to assign the page that is to be processed to $_. This is one way
to make use of the program:
sub striphtml {
local $_ = shift;
do 'striphtml.pl';
$_
}
$page = striphtml($page);
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Piping output to and from external perl routine

2004-10-15 Thread John W. Krahn
Dan Fish wrote:
Is there an easy way to pipe output to an external perl routine and then
pipe the output of that routine back in for more processing?
In particular I want to use LWP::UserAgent to grab a web page, pipe the
output to Tom Christiansen's "striphtml" routine
(http://www.cpan.org/authors/Tom_Christiansen/scripts/striphtml.gz) and then
pipe that output back in for some subsequent processing.  Something like:
my $ua = new LWP::UserAgent;
my $request = new HTTP::Request('GET', $myURL);
my $response = $ua->request($request);
my $page = $response->content;
open(STRIPHTML, "|striphtml.pl") || die("Can\'t open striphtml: $!\n");
print STRIPHTML $page;
close(STRIPHTML); # maybe not such a good idea?
This works fine so far... But now what?  How do I get the output of
striphtml.pl back in to do some more processing on it?
I know I can do this with a temporary file, but I loathe using them when
reasonable alternatives might be available...
Copy and paste Tom's code into your program.
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Piping output to and from external perl routine

2004-10-16 Thread John W. Krahn
Dan Fish wrote:
Yes... I could do that, and HAVE actually done that before for other
routines due to the "fire-fighting" time constraints of the moment :-)  This
time I was hoping to increase my *very-limited* knowledge of Perl for a more
elegant solution, because I'm sure I'll need to do something similar
again...
Gunnar's response actually worked quite well... (Thanks Gunnar!)
sub striphtml {
 local $_ = shift;
 do 'striphtml.pl';
 $_
}
	$page = striphtml($page);
Yes, but that is less efficient as you have to read and compile a separate 
file at runtime.

John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: Piping output to and from external perl routine

2004-10-16 Thread Dan Fish
< original request snipped>

> 
> Copy and paste Tom's code into your program.
> 

Yes... I could do that, and HAVE actually done that before for other
routines due to the "fire-fighting" time constraints of the moment :-)  This
time I was hoping to increase my *very-limited* knowledge of Perl for a more
elegant solution, because I'm sure I'll need to do something similar
again...

Gunnar's response actually worked quite well... (Thanks Gunnar!)

sub striphtml {
 local $_ = shift;
 do 'striphtml.pl';
 $_
}

$page = striphtml($page);


-Dan


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]