-
Notifications
You must be signed in to change notification settings - Fork 0
/
ltp.pl
77 lines (75 loc) · 1.97 KB
/
ltp.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Perl check Skeleton
#!/usr/bin/perl -w
######################### ltp.pl #################
my $Version='0.1';
my $check_name='ltp.pl';
# Date : Jun 8 2022
# Author : Paul AZEMA (rigonkmalk at gmail dot com)
# Generic skeleton for perl check.
################################################################
use strict;
use Getopt::Long;
use Switch;
use Data::Dumper;
### Global vars declaration
my ($o_help,$o_textinput,$input);
my $output='';
my %reverse_exit_code = (
'Ok' => 0,
'Warning' => 1,
'Critical' => 2,
'Unknown' => 3,
);
### Vars array definition
my %dict;
$dict{$_} = '0' for qw(0);
$dict{$_} = '1' for qw(1);
$dict{$_} = '2' for qw(a b c 2);
$dict{$_} = '3' for qw(d e f 3);
$dict{$_} = '4' for qw(g h i 4);
$dict{$_} = '5' for qw(j k l 5);
$dict{$_} = '6' for qw(m n o 6);
$dict{$_} = '7' for qw(p q r s 7);
$dict{$_} = '8' for qw(t u v 8);
$dict{$_} = '9' for qw(w x y z 9);
$dict{$_} = '*' for qw(@ # $ % ^ * - _ + =);
### Function declaration
sub usage {
print "\nLetter To Number '.$check_name.' for Wildix. Version ",$Version,"\n";
print "GPL Licence - Paul AZEMA\n\n";
print <<EOT;
-h, --help
print this help message
-i, --input=HOST
char or number to convert
EOT
exit $reverse_exit_code{Unknown};
}
sub get_options () {
Getopt::Long::Configure ("bundling");
GetOptions(
'h|help' => \$o_help,
'i|input:s' => \$o_textinput
);
usage() if (defined ($o_help));
usage() if (! defined ($o_textinput));
$o_textinput=lc($o_textinput); # Set input to lower case
}
sub output_display () {
print $output;
exit $reverse_exit_code{Ok};
}
### Main
get_options();
my @text = split ("",$o_textinput);
###print Dumper(@text);
printf "Do not take care of %% on the end.\n";
foreach (@text) {
switch ($_) {
case (\%dict) {
$output = $output.$dict{$_};
}
else { printf 'Unrecognized character in chain '.$_."\n"; exit 128; }
}
}
output_display();