Skip to content

Instantly share code, notes, and snippets.

@earnhardt3rd
Last active January 7, 2024 02:00
Show Gist options
  • Save earnhardt3rd/9cbfe34671a68caf4b93f411cbae1eb3 to your computer and use it in GitHub Desktop.
Save earnhardt3rd/9cbfe34671a68caf4b93f411cbae1eb3 to your computer and use it in GitHub Desktop.
sub fromARRAY {
print " =============== FROM ARRAY ===============\n" if $DEBUG > 0;
my @ARRAY = @_;
if (scalar(@ARRAY) <= 0) {return;}
my @RETURN;
my $ans="";
my $len = length(scalar(@ARRAY));
if (uc($MODE) !~ /NO-PROMPT/) {
for (my $i=0;$i<=scalar(@ARRAY)-1 ;$i++) {
my $c = $i+1;
printf " %-${len}s %-s\n",$c,$ARRAY[$i];
}
print "\n\tEnter Choice (x~exit| s~skip | n~new) 1,2,ect | 1-5,8-19 | a for all] [a]:";
$ans = <STDIN>;
chomp($ans);
print "\n";
if (lc($ans) eq "x") {
&_EXIT_CLEAN("Exit by user!");
}
if (lc($ans) eq "s") {return;}
}
if ($ans eq "") {
$ans = "a";
}
if ($ans eq "a") {
print "\t\tLoading All...\n" if $DEBUG > 0;
for my $f(@ARRAY) {
push(@RETURN,$f);
}
} else {
my @INPUT = split(',',$ans);
my $test="";
for my $line(@INPUT) {
print " *** Looking for Input ($line-1) :" if $DEBUG > 0;
my ($s,$e) = split('-',$line);
if (! defined $e) {$e="";}
if ($e eq "") {
$test = $s;
$test =~ s/[aA-zZ]//g;
if ($test ne "") {
if ($ARRAY[$s-1] ne "") {
print "Found SPECIFIC: " . $ARRAY[$s-1] . " ***\n" if $DEBUG > 0;
push(@RETURN,$ARRAY[$s-1]);
}
}
} else {
for (my $int=$s;$int<=$e ;$int++) {
$test = $int;
$test =~ s/[aA-zZ]//g;
if ($test ne "") {
if ($ARRAY[$int-1] ne "") {
print "Found RANGE" . $ARRAY[$int-1] . " ***\n" if $DEBUG > 0;
push(@RETURN,$ARRAY[$int-1]);
}
}
}
}
}
}
print " FROM_ARRAY_RETURN_LIST:\n" if $DEBUG > 0;
if (scalar(@RETURN) > 0) {
for (my $ix=0;$ix<=scalar(@RETURN)-1 ;$ix++) {
print " --$ix $RETURN[$ix]\n" if $DEBUG > 0;
}
} else {
if ($ans ne "") {push(@RETURN,$ans);}
}
return @RETURN;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment