On 4/13/05, John Doe <[EMAIL PROTECTED]> wrote: > Am Mittwoch, 13. April 2005 10.46 schrieb Ramprasad A Padmanabhan: > > 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 It depends how complex your options are going to be, but if you really want to do it "like gnu", take a look at Getopt::Std and Getopt::Long.
--jay -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>