[Kc] say STDOUT and warn STDERR
Chris Stinemetz
chrisstinemetz at gmail.com
Wed Mar 7 12:14:43 PST 2012
On Wed, Mar 7, 2012 at 1:53 PM, Jonathan Otsuka <djgoku at gmail.com> wrote:
> I am using getopt::long so I could add another parameter, but sometimes I
> want to see the data before I save it to a file.
>
> I think I am going to change lines that I want to output to the screen if I
> redirect STDOUT or not to:
>
> # since STDERR filehandle is already open for us
> print STDERR "blah";
>
> Instead of using:
>
> warn "blah";
>
> Jonathan Otsuka
This is how I would handle it without using getopt modules.
use warnings;
use strict;
my $OUTPUT;
my $outFile = "out.txt";
print "Would you like STDOUT and STDERR on CLI? \[yes no\]\n";
while ( $OUTPUT = <STDIN> ) {
if ( $OUTPUT =~ /[yY]es/ ) {
$OUTPUT = 1;
last;
}
if ( $OUTPUT =~ /[nN]o/ ) {
$OUTPUT = 0;
last;
}
}
open my $out,'>',$outFile or die "ERROR opening $outFile: $!" if $OUTPUT == 0;
print "STDOUT and STDERR you chose Yes\n" if $OUTPUT == 1;
print $out "You chose No\n" if $OUTPUT == 0;
print "Check the file out.txt\n" if $OUTPUT == 0;
More information about the kc
mailing list