Skip to content

Instantly share code, notes, and snippets.

@earnhardt3rd
Created June 19, 2023 13:56
Show Gist options
  • Select an option

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

Select an option

Save earnhardt3rd/ef6c604edb07d8d97de59da13b36bb41 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 = &fromARRAY_WITH_DEFAULT();}
1;
sub fromARRAY_WITH_DEFAULT {
my $input = shift || "s";
print " =============== FROM ARRAY ===============\n" if $DEBUG > 0;
my @ARRAY = @_;
MNU:
my $ans = $input;
my %RETURN;
if (uc($MODE) ne "CRON") {
if (scalar(@ARRAY) > 0) {
for (my $i=0;$i<=scalar(@ARRAY)-1 ;$i++) {
my $c = $i+1;
print "\t$c $ARRAY[$i]\n";
}
print "\n\tEnter Choice (x~exit| s~skip | n~new) 1,2,ect | 1-5,8-19 | a for all] [$ans]:";
$ans = <STDIN>;
chomp($ans);
print "\n";
if (lc($ans) eq "x") {
&_EXIT_CLEAN("Exit by user!");
}
if ($ans eq "") {$ans = $input;}
if (lc($ans) eq "s") {return;}
if (lc($ans) eq "n") {
print " Enter New Value (x~exit| s~skip ) [$ans]:";
my $ans = <STDIN>;
chomp($ans);
if (lc($ans) eq "x") {
&_EXIT_CLEAN("Exit by user!");
}
if ($ans eq "") {$ans = $input;}
if (lc($ans) eq "s") {return;}
$RETURN{$ans}="";
}
} else {
print " Enter Value (x~exit| s~skip ) [$ans]:";
my $ans = <STDIN>;
chomp($ans);
if (lc($ans) eq "x") {
&_EXIT_CLEAN("Exit by user!");
}
if ($ans eq "") {$ans = $input;}
if (lc($ans) eq "s") {return;}
$RETURN{$ans}="";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment