#!/usr/bin/perl # # PM_help.pl FileName - Prints contents of file FileName # PM_help.pl -test - Prints contents of handle # PM_help.pl - Prints contents of STDIN # use strict; use warnings; use IO::Handle; # Prepare the selected filehandle my $FName=shift; my $FH = new IO::Handle; if (! defined $FName) { $FH->fdopen(fileno(STDIN), "r") or die "Can't grab STDIN!\nErrMsg: $!\n"; } elsif ($FName eq "-test") { # I was hoping one of these two would work, but no luck #$FH->fdopen(fileno(DATA), "r") # or die "Can't grab DATA!\nErrMsg: $!\n"; #$FH->new_from_fd(fileno(DATA), "r") # or die "Can't grab DATA!\nErrMsg: $!\n"; # Works, but I don't care for it open $FH, '<', $0 or die "Can't open '$0'\nErrMsg: $!\n"; while (<$FH>) { last if /^__DATA__\s*$/; } } else { open $FH, '<', $FName or die "Can't open '$FName'\nErrMsg: $!\n"; } # Use the file... while (<$FH>) { print "$.: $_"; } # EXAMPLE DATA __DATA__ The quick red fox jumped over the lazy brown dog. Now is the time for all good men to come to the aid of their party.