#! /usr/bin/perl

# pl-cat --
# 	template file for perl scripts, that read from stdin if no args,
# 	else read from filenames, passed on args...
# 	
# $Id$
# Carlos Duarte <cgd@mail.teleweb.pt>, 990218

use strict;

sub usage {
	print <<EOM;
usage: $0 [-n] [-h] options args ... 

  -h      this help
  -n      dont! do nothing. 
EOM
	@_ and print "\n", join("\n", @_), "\n";
	exit;
}

O: while (defined(my $opt = shift)) {
	$opt eq "-h" and usage;

	# option with no args... (flag)
	$opt eq "-n" and do { next O; }; 

	# option with one arg
	$opt =~ /^-f/ and do {
		$opt =~ s///; ($opt eq "" && !defined($opt = shift)) and usage;
		# use $opt
		next O; 
	}; 

	## more options here... 

	$opt eq "--" and last O;
	$opt =~ /^-/ and usage; 
	unshift(@ARGV, $opt); 
	last O; 
}

if (@ARGV == 0) {
	&do_it(\*STDIN); 
} else {
	my $file; 

	while (defined($file = shift)) {
		open(F, $file) or die "opening $file, $!"; 
		&do_it(\*F); 
		close(F) or warn "closing $file, $!"; 
	}
}

sub do_it {
	my $FH = shift; 

	# insert code here, using $FH as input read file handler...
	while (<$FH>) {
		print; 
	}
}

