I am trying to come up with some logic to give my script an option of where to send the output.
This is a test script I started to write, I started to fizzle out trying to think of the combonations of the two options. I know I am overthinking this too much.
#!/usr/bin/perl
use strict;
use warnings;
# Modules to load
use Getopt::Long;
use Term::ANSIColor qw(:constants);
my $output = 0;
my $logfile = '';
GetOptions(
'o' => \$output,
'l' => \$logfile
);
if (($output == 1) && (! $logfile eq '')){
} elsif (($output == 0)($logfile eq '')){
}
If this is of any use be my guest.
Pretty much I want 3 options
0 = off
1 = stdout
2 = logfile
Where I threw a bit of a wrench at myself if when I wanted to add a custom logfile argument. I am under the impression I cannot combine the 2 arg into the same arg, can I?
The places where I will have output to write, I will control with simple if statments based on a condition, in my first interation which just allows for output to stdout. I just used the -o option and specified 0 or 1. If it was 1 it wrote the line, if it was 0 it did not.
If any has an easier solution than the one above I am open to anything.
Thanks in advance.
In the vein of TLP I suggest a
$verboseand a$logfileoption, I would also recommend that$verbosebe implicitly set to true if$logfileis used. Use$verboseto controlprintcommands as usual. The big magic is to useselectto control where theprintsends its output if no filehandle is given.Also since
Getopt::Longgives you long options, I have changed the options names to the human readableverboseandlogfile, however you can use short-vor long--verboseto your taste.