[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lon-capa-users
Subject:    [LON-CAPA-users] variables and customrespone
From:       Peter Dencker <dencker () math ! uni-luebeck ! de>
Date:       2013-01-31 21:55:56
Message-ID: 510AE86C.7020107 () math ! uni-luebeck ! de
[Download RAW message or body]

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>

_______________________________________________
LON-CAPA-users mailing list
LON-CAPA-users@mail.lon-capa.org
http://mail.lon-capa.org/mailman/listinfo/lon-capa-users
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic