in reply to Filehander Question
#!/usr/bin/perl use strict; use warnings; use Getopt::Std; my $opt = {}; Get_Args( $opt ); my $fh; if ( $opt->{o} ) { open ( $fh, '>', $opt->{o} ) or die "Unable to open $opt->{o} for +writing : $!"; } else { open ( $fh, '>&', *STDOUT ) or die "Unable to dup STDOUT : $!"; } select $fh; $| = 1; print "foo bar\n"; sub Get_Args { my $opt = shift; my $Usage = qq{Usage: $0 [options] -h : This help message. -o : Output file - STDOUT by default } . "\n"; getopts( 'ho:' , $opt ) or die $Usage; die $Usage if $opt->{h}; }
Cheers - L~R
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Filehander Question
by ikegami (Patriarch) on Oct 07, 2004 at 15:33 UTC | |
by Limbic~Region (Chancellor) on Oct 07, 2004 at 15:38 UTC | |
by ikegami (Patriarch) on Oct 07, 2004 at 15:39 UTC | |
by Limbic~Region (Chancellor) on Oct 07, 2004 at 15:46 UTC |