Skip to content

Instantly share code, notes, and snippets.

@cou929
Created January 4, 2011 15:56
Show Gist options
  • Save cou929/764949 to your computer and use it in GitHub Desktop.
Save cou929/764949 to your computer and use it in GitHub Desktop.
Read file if the command line argument is specified, or read from standard input.
#! /usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
use Pod::Usage;
# global variables
my $help = 0;
my $man = 0;
GetOptions(
'help|h' => \$help,
'man' => \$man
) or pod2usage();
pod2usage(1) if $help;
pod2usage(-exitstatus => 0, -verbose => 2) if $man;
&main; exit;
sub main {
my $handle = 'STDIN' unless $ARGV[0];
(open $handle, "<", $ARGV[0] or die "Cannot open $ARGV[0], $!") if $ARGV[0];
while (<$handle>) {
print;
}
}
# functions
__END__
=head1 NAME
input.pl - Write short description of this script here
=head1 SYNOPSIS
input.pl [options] [file ...]
Options:
-help, h brief help message
-man full documentation
=head1 OPTIONS
=over 2
=item B<-help, h>
Print a brief help message and exits.
=item B<-man>
Prints the manual page and exits.
=back
=head1 DESCRIPTION
B<This program> will read the given input file(s) and do something
useful with the contents thereof.
=cut
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment