Skip to content

Instantly share code, notes, and snippets.

@earnhardt3rd
Created June 19, 2023 14:03
Show Gist options
  • Select an option

  • Save earnhardt3rd/4b15a6ef0f91df4f38c1ec717e1d7a7d to your computer and use it in GitHub Desktop.

Select an option

Save earnhardt3rd/4b15a6ef0f91df4f38c1ec717e1d7a7d to your computer and use it in GitHub Desktop.
require 'getopts.pl';
Getopts('m:d:t');
my $MODE = uc($opt_m) || "";
my $DEBUG = $opt_d || 0;
if (defined $opt_t) { my %TEST = &_RUN_SUB();}
1;
sub _RUN_SUB {
my $rs_input = shift || "";
print " _RUN_SUB($rs_input)\n" if $DEBUG > 1;
my %RS = &_INPUT_2_HASH($rs_input);
my $sub_name="";
my $sub_parm="";
my $sub_rtn = "";
if (scalar(keys %RS) > 0) {
if (exists($RS{"SUB"})) {
$sub_name=$RS{"SUB"};
}
if (exists($RS{"PARM"})) {
$sub_parm=$RS{"PARM"};
}
if ($sub_name eq "") {
if (exists($RS{"NO_TAG"})) {
if ($RS{"NO_TAG"} =~ /\|/) {
my @NT = split('\|',$RS{"NO_TAG"});
for (my $ni=0;$ni<=scalar(@NT)-1 ;$ni++) {
if ($NT[$ni] eq "INT") {
print " _RUN_SUB:INFO: Skip INT\n" if $DEBUG > 1;
next;
}
if ($sub_name eq "") {
$sub_name=$NT[$ni];
} else {
if ($sub_parm eq "") {
$sub_parm=$NT[$ni];
} else {
print " _RUN_SUB:WARN: Unused parameter:]$NT[$ni]\n" if $DEBUG > 1;
}
}
}
} else {
$sub_name=$RS{"NO_TAG"};
}
}
}
}
if (scalar(keys %SUBS) <= 0) {&_GET_SUBS();}
if (uc($MODE) ne "CRON") {
if ($sub_name eq "") {
my @SLIST = keys %SUBS;
@SLIST=sort @SLIST;
my $sMsg = "\n";
$sMsg.= " .. WARNING! WARNING! WARNING! .. \n";
$sMsg.= " .. ^^ .. \n";
$sMsg.= " .. BE VERY CAREFUL WITH THIS! .. \n";
$sMsg.= " .. ^^ .. \n";
$sMsg.= " .. WARNING! WARNING! WARNING! .. \n";
$sMsg.= " .. ^^ .. \n";
$sMsg.=" \n";
&displayMessageInBox($sMsg);
unshift(@SLIST,"Please Select the SubProcudure to Run");
$sub_name = &fromARRAY_SINGLE_W_TITLE(@SLIST);
}
if ($sub_parm eq "") {
print " Enter parameters for SUB[$sub_name]:";
$sub_parm = <STDIN>;
chomp($sub_parm);
}
}
if ($sub_name eq "") {return;}
print " _RUN_SUB[$sub_name($sub_parm)]\n" if $DEBUG > 1;
if ($sub_name !~ /^_PUB/) {
printf " --NON PUBLISHED SUB:%-40s:",$sub_name;
if (!exists($SUBS{$sub_name})) {
printf "%-15s","INVALID";
if (exists($SUBS{"_PUB" . $sub_name})) {
$sub_name="_PUB" . $sub_name;
printf "%-15s AS %-s\n","FOUND PUBLISHED",$sub_name;
} else {
print "\n";
}
} else {
printf "%-15s\n","IS VALID!";
}
}
if (exists($SUBS{$sub_name})) {
my $iSub = $SUBS{$sub_name};
$sub_rtn = &{$iSub}($sub_parm) || "";
} else {
$sub_rtn = "ERROR! Unable to find internal sub-procedure:$sub_name";
}
if ($sub_rtn ne "") {
if ($sub_parm ne "WAIT") {
&displayMessageInBox($sub_rtn);
}
}
return $sub_rtn;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment