On Wed, 2005-04-13 at 12:32, Thomas BÃtzler wrote:
> Ramprasad A Padmanabhan <[EMAIL PROTECTED]> asked:
> > I want to write a perl script like "gnu less".
> > 
> > My perl script accepts input on STDIN or filename(s) as arguments. 
> > If both are missing it should print the error message. How do 
> > I do this ?
> 
> There is always input on STDIN - even a straight eof could be input,
> like in "cat empty_file | ramprasads_less". You should probably try
> and check for filename arguments and revert to STDIN processing if
> there are none, i.e.
> 
> my @files;
> 
> if( @ARGV ){
>   @files = @ARGV;
> } else {
>   @files = ("-");
> }
> 
> foreach my $file (@files){
>   # transparent gzip decompression
>   $file = "/usr/bin/gzip -d < $file|" if $file =~ m/\.gz$/;
> 
>   open( IN, $file ) or die "Cam't open '$file': $!";
>   # do something
>   close( IN );
> }
> 
> HTH,
> Thomas

That is perfectly ok .. but I require to print usage if there is no
input How do I do this ? 

Thanks
Ram


----------------------------------------------------------
Netcore Solutions Pvt. Ltd.
Website:  http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
----------------------------------------------------------

-- 
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