[LON-CAPA-users] variables and customrespone

Peter Dencker dencker at math.uni-luebeck.de
Thu Jan 31 16:55:56 EST 2013


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';


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

<script type="loncapa/perl">

  $message ='';

<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'
  <customhint id="r0h0">
    <answer type="loncapa/perl">
      unless ( $submission =~  /^\s*[-+]?\s*\d+\s*$/ ) {
          ## the same test

          $message = "Submission is not an integer number."

  <startouttext />
    <br /> <textline readonly="no" /> <br />


  <endouttext />

More information about the LON-CAPA-users mailing list