gg48gg has asked for the wisdom of the Perl Monks concerning the following question:
Hi all, I am trying to use a file if a file is given by the user, otherwise use STDIN. It is not working, and I am not sure of the best way to do this. I could use some advice. I suspect I need some honing of my understanding of using variables with filehandles.
if ($FILE) { open(FILE,"<",$FILE) || fatal_error("Unable to open file $FILE"); $HANDLE='FILE' } else { $HANDLE='STDIN'; } ###################################################################### +########## #MAIN ###################################################################### +########## while (defined(my $line = <$HANDLE>)) { print "$line"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to select a file handle depending on user options
by choroba (Cardinal) on Jun 18, 2012 at 21:53 UTC | |
|
Re: How to select a file handle depending on user options
by morgon (Priest) on Jun 18, 2012 at 23:14 UTC | |
by gg48gg (Sexton) on Jun 20, 2012 at 13:32 UTC | |
|
Re: How to select a file handle depending on user options
by linuxkid (Sexton) on Jun 19, 2012 at 20:29 UTC |