[EMAIL PROTECTED] wrote:

> 
> Case 3. (this is the difficult case for me) the script is invoked
> with no file and no pipe to it.  I would like the script to
> end quietly, such as
>>test.input.source
>>
> 
> Instead, it waits for input.
> 
>> test.input.source
> no command line args - switching to STDIN
> 
> 
> and now it waits forever.

select / IO::Select is what you are looking for. i suggested the following 
to someone who asked exactly the same question a while back. if you have 
searched this group hard enough, you would have found the solution:

#!/usr/bin/perl -w
use strict;

#--
#-- script.pl
#--

use IO::Select;

if(@ARGV){
        print join("\n", "get file: ",@ARGV) . "\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]$ script.pl
no input
[panda]$ script.pl file.html
get file:
file.html
[panda]$ echo "hi" | script.pl
get line hi
[panda]$

perldoc -f select
perldoc IO::Select

david
-- 
sub'_{print"@_ ";* \ = * __ ,\ & \}
sub'__{print"@_ ";* \ = * ___ ,\ & \}
sub'___{print"@_ ";* \ = * ____ ,\ & \}
sub'____{print"@_,\n"}&{_+Just}(another)->(Perl)->(Hacker)

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to