Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save earnhardt3rd/00de938df28909ab1d7d63853b0aaefd to your computer and use it in GitHub Desktop.
sub fromARRAY {
print " =============== FROM ARRAY ===============\n" if $DEBUG > 0;
my @ARRAY = @_;
my @RETURN;
my $ans="";
if ($MODE ne "NO-PROMPT") {
for (my $i=0;$i<=scalar(@ARRAY)-1 ;$i++) {
my $c = $i+1;
printf " %-4s %-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 .ftp files\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