-
Notifications
You must be signed in to change notification settings - Fork 0
/
fab.pl
74 lines (67 loc) · 1.78 KB
/
fab.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
#!/usr/bin/perl
use strict;
use warnings;
sub Calculate_FAB_TotalScore {
my @fab_items = (
'similatiries (conceptualisation)',
'lexical fluency (mental flexibility)',
'motor series (Luria) test (programming)',
'conflicting instructions (sensitivity to interference)',
'Go-No Go (inhibitory control)',
'prehension behaviour (environmental autonomy)',
);
my %fab_scores;
# Get user input for each FAB item
foreach my $item (@fab_items) {
my $valid_input = 0;
while (!$valid_input) {
print "Please, type score for: $item [0-3]: ";
my $score = <STDIN>;
chomp($score);
# Validate input
if ($score =~/^\d+$/ && $score >= 0 && $score <= 3) {
$fab_scores{$item} = $score;
$valid_input = 1;
}
else {
print "Invalid input. Please, type results between 0 and 3. ";
}
}
}
# Calculate the total FAB score
my $total_score = 0;
foreach my $item_score (values %fab_scores) {
$total_score += $item_score;
}
return $total_score;
}
# Main Programme
print "Frontal Assessment Battery (FAB) calculator\n";
print "===========================================\n";
my $total_fab_score = Calculate_FAB_TotalScore();
# Print the total score of FAB
print "\nThe total FAB score is $total_fab_score/18\n";
while (1) {
print "Do you want to save the output to file (fab.txt) [yes or no]? ";
my $ans = lc(<STDIN>);
chomp($ans);
if ($ans eq 'yes') {
my $output = 'fab.txt';
open(FH,'>', $output) or die $!;
print FH
my $str = <<END;
The Frontal Lobe Assessment Battery Score (FAB) is $total_fab_score/18
END
# print FH $str;
close(FH);
print "written to fab.txt\n";
last;
}
elsif ($ans eq 'no') {
print "not saved\n";
last;
}
else {
print "out of range, please answer [yes or no] ";
}
}