{
  "id": "04",
  "content": [
    {
      "type": "heading",
      "text": "Subroutines, Context & References"
    },
    {
      "type": "text",
      "html": "Subroutines are declared with <code>sub</code>; Perl has scalar and list context."
    },
    {
      "type": "text",
      "html": "<pre><code>sub add { my ($a,$b)=@_; return $a+$b; }\nmy $x = add(2,3); # 5\n</code></pre>"
    },
    {
      "type": "text",
      "html": "References let you build complex structures: <code>my $aref = \\@array;</code>, <code>my $href = \\%hash;</code>. Dereference with <code>@{$aref}</code> / <code>%{$href}</code>."
    }
  ],
  "quiz": {
    "questions": [
      {
        "id": "q1",
        "type": "single",
        "text": "Which keyword defines a subroutine?",
        "options": [
          {
            "id": "a",
            "text": "sub"
          },
          {
            "id": "b",
            "text": "func"
          },
          {
            "id": "c",
            "text": "def"
          }
        ],
        "correct": [
          "a"
        ]
      },
      {
        "id": "q2",
        "type": "single",
        "text": "What does <code>\\@array</code> produce?",
        "options": [
          {
            "id": "a",
            "text": "An array reference"
          },
          {
            "id": "b",
            "text": "A copy of the array"
          },
          {
            "id": "c",
            "text": "A hash"
          }
        ],
        "correct": [
          "a"
        ]
      }
    ]
  }
}