19. Short-Term Memory Test

A short-term memory test is a cognitive assessment designed to measure an individual's ability to temporarily hold and manipulate information over a short period of time. When conducting a short-term memory test, it's important to use a variety of words to assess a person's memory capacity and recall ability. My Perl application is a basic one: the user should write by hand the words he could recall. Each word is presented 2 seconds. A 13 words list is used.

use Prima qw(Buttons Label Application Widget::Time);

$app_width = 450;
$mw = Prima::MainWindow-> create(
	text => "Short-Term Memory Test",
	sizeMin => [$app_width, 200],
	sizeMax => [$app_width, 200], 
	icon => Prima::Icon-> load('icon.png'),		
);

$intro_text = $mw-> insert( "Label",
    origin => [0, 140],
    size => [$app_width, 100],   
    text => "Remember the words you'll see! \nClick the Start button.",
    wordWrap => 1,
    font => { size => 12, },	
    alignment => ta::Center,
    autoHeight => 1,
); 

$task_field = $mw-> insert( 
    Label => 
          origin => [0, 75],
          size => [$app_width, 50],
          text => "",
          alignment => ta::Center,	          
          wordWrap => 1,          
          font => { size => 26, },
          color => cl::Yellow,
);

@items = qw( Car Zebra Guitar Hat Lemon Tiger Teapot Orange Penguin Socks Rainbow Notebook House );
@items_copy;

$show_button;

# The most interesting part of this code: a Timer object with the onTick property using shift for presenting the words!
# Shift 'eats' the items of an array. Hence @items_copy.

$mw-> insert( Timer =>
        name => 'mcTimer',
        timeout => 2000,
        onTick  => sub { @items_copy ? $task_field->text(shift @items_copy) 
				     :	
					( $mw-> mcTimer-> stop, 
					  $task_field-> text(""), 
					  $show_button-> enabled(1),
					  $intro_text-> text("Recall the words you saw!")
					), 
			},
);

$mw-> insert( 	           
            Button =>
                origin => [(($app_width/2)-75), 25],
                size      => [75, 30],
                text      => "Start",
                color     => 0x000000,
                backColor => 0xcccccc,
                onClick   => sub { 
					
					$intro_text-> color(cl::White),
					$intro_text-> text("Remember the words you'll see!\nClick the Start button."),
					@items_copy = @items,
					$show_button-> enabled(0),
					$mw-> mcTimer-> start;
				 },
);   

$show_button = $mw-> insert( 	           
            Button =>
                origin => [(($app_width/2)), 25],
                size      => [75, 30],
                text      => "Show",
                color     => 0x000000,
                backColor => 0xcccccc,
                onClick   => sub { 
					$intro_text-> text("@items"),
					$intro_text-> color(cl::Green),
                                 },
                enabled => 0,                 
); 

run Prima;