[LON-CAPA-users] variables and customrespone

Hi,
can I use the value of a variable, changed between the <answer>,
</answer> tags in
<customresponse id="r0">
<answer type="loncapa/perl">
$variable = 'some value';
</answer>
</customresponse
outside this customresponse?
Defining it in an additional customhint works. But often I use the same
extensive tests on the $submission and have to do it twice. This is not
really a problem, as I can write a sub in an outside perl script. But I
wonder whether I have to do so. I give a simple example below.
-- Peter
<problem>
<script type="loncapa/perl">
$message ='';
</script>
<startouttext />
Give an odd integer number.
<endouttext />
<customresponse id="r0">
<answer type="loncapa/perl">
unless ( $submission =~ /^\s*[-+]?\s*\d*\s*$/ ) {
$message = "Submission is not an integer number.";
## value of $message is not changed outside
## (comment out the same line in the customhint)
return 'BAD_FORMULA'
}
if ( $submission % 2 == 1 ) { return 'EXACT_ANS' }
return 'INCORRECT'
</answer>
<customhint id="r0h0">
<answer type="loncapa/perl">
unless ( $submission =~ /^\s*[-+]?\s*\d+\s*$/ ) {
## the same test
$message = "Submission is not an integer number."
}
</answer>
</customhint>
</customresponse>
<startouttext />
<br /> <textline readonly="no" /> <br />
$message
<endouttext />
</problem>