Creation of custom perl functions for reuse

I have written a perl function that retrieves the current question number (you can see it below but is not relevant here). Which I want to use in each Question Header1.

I am asking myself if there is a possibility to save this code as a function (like getQuestionNumber()) somewhere and then simply call the function instead copy pasting the code all the time? This would make the survey code better readable and easier to maintain.

For Javascript that should be doable in the SSI_admin_javascript file, but what about perl?

[% Begin Unverified Perl
# Code to get current Questionnumber
my $startPageNumber = 2;

my $currentPageNumber = PAGENUMBER;
my $maxPageNumber = GETVALUE("HiddenCounter_MaxPageNumber");
my $currentQuestion = GETVALUE("HiddenCounter_Question");

if($currentPageNumber >= $maxPageNumber){
	SETVALUE("HiddenCounter_MaxPageNumber", $currentPageNumber);
	SETVALUE("HiddenCounter_Question", $currentQuestion + 1);
	
	return $currentQuestion; # currentQuestion has still the value before HiddenCounter_Question was increased by one
}
elsif($currentPageNumber < $maxPageNumber){
	SETVALUE("HiddenCounter_Question", $currentQuestion - 1);
	return $currentQuestion - 2;
}
End Unverified %]

KR Florian

3 replies