perl/unix question
    Rob Ransbottom 
    rir at mediaone.net
       
    Thu Aug  2 10:44:35 EDT 2001
    
    
  
On Wed, 1 Aug 2001 bpmedley at 4321.tv wrote:
# Below are examples:
# 
# ./script.pl
# always prompt
# 
# ./script.pl file -
# no prompting when parsing 'file'
# prompt when parsing '-'
# 
# ./script.pl file
# never prompt
# 
# echo input | ./script.pl
# never prompt
# 
# echo input | ./script.pl file -
# never prompt
#!/usr/bin/perl -w
use strict;
# I'd start like this, this is off the cuff, beware.  XXX
my $on_pipe = 1;
$on_pipe = 0 if ( -t STDIN && -t STDOUT);  # maybe just STDIN
die "In pipe\n" if -t STDOUT ;  # if you want this
# this seems to be what you described, but usually
# I'd search for - and have the user finish
# their work right away.
$ARGV[0] = "-" if ( !on_pipe && @ARGV == 0);
foreach my $arg ( @ARGV ) {
   if ($arg eq "-" ) { 
      die "user input not allowed when on pipe" if $on_pipe;
      # query user
      # prep input
      &process_input;
      # finalize input
   }elsif ( $arg =~ /^-.+/ ) {  # or accept as a filename XXX
      die "commandline option not anticipated";
   }else{
      # prep file 
      &process_input;
      # finalize file
   }
}
sub process_input { 1; # XXX stub
}
-
Subcription/unsubscription/info requests: send e-mail with
"subscribe", "unsubscribe", or "info" on the first line of the
message body to discuss-request at blu.org (Subject line is ignored).
    
    
More information about the Discuss
mailing list