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