Assuming you are writing this script yourself, or can edit it, something like below will work.
use Getopt::Long;
our $VERBOSE = 0;
GetOptions ('verbose+' => \$VERBOSE);
# ...
xprint(1, "Yadda yadda yadda");
# ...
sub xprint {
my ($pri, $msg) = @_;
print("$msg\n") if $pri >= $VERBOSE;
}
EDIT:
Or without priority levels:
use Getopt::Long;
our $VERBOSE = '';
GetOptions ('verbose' => \$VERBOSE);
# ...
xprint("Yadda yadda yadda");
# ...
sub xprint {
# can also be replaced with printf(@_) for more cowbell.
print("$_[0]\n") if $VERBOSE;
}
EDIT:
As an aside, for #ifdef
functionality, replace the whole getopt section with a simple constant:
use constant VERBOSE => 1;
And remove the $
from VERBOSE after the print statement:
print("$_[0]\n") if VERBOSE;