Kevin Pfeiffer wrote:
> In article <[EMAIL PROTECTED]>, John W. Krahn wrote:
>
>> "R. Joseph Newton" wrote:
>>>
>>> Kevin Pfeiffer wrote:
>>>
>>> > I'm looking at HTML::TokeParser. It expects a scalar with a filename
>>> > or a reference to a scalar containing the data to parse.
>>> >
>>> > This works fine:
>>> >
>>> > my $html;
>>> > if (@ARGV) { # get filename for
>>> > TokeParser
>>> > $html = shift;
>>> > } else {
>>> > my @html = <>;
>>>
>>> Where is the diamond operator here supposed to be filled from?
>>
>> <> treats the elements of @ARGV as file names and opens them in order
>> and returns their contents but if @ARGV is empty it returns the contents
>> of STDIN.
>
> This is what I'm stuck on - is there a way to determine if STDIN is
> getting/is going to get/has gotten any contents?
>
this might be a little late but the select(r,w,e,t) syscall is what you
need. the IO::Select module (standard) has a nice OO interface to setting
up the correct mask for you:
#!/usr/bin/perl -w
use strict;
#-- html.pl
use IO::Select;
if(@ARGV){
my $filename = shift;
print "get file $filename\n";
}else{
my $buf;
my $line;
my $io = IO::Select->new(\*STDIN);
while($io->can_read(0)){
last unless(sysread(STDIN,$buf,1024));
$line .= $buf;
}
if(defined $line){
print "get line $line";
}else{
print STDERR "no input\n";
}
}
__END__
[panda]$ html.pl
no input
[panda]$ html.pl file.html
get file file.html
[panda]$ echo "hi" | html.pl
get line hi
[panda]$
perldoc -f select
perldoc IO::Select
david
--
$_=q,015001450154015401570040016701570162015401440041,,*,=*|=*_,split+local$";
map{~$_&1&&{$,<<=1,[EMAIL PROTECTED]||3])=>~}}0..s~.~~g-1;*_=*#,
goto=>print+eval
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]