title: How can I modify a scalar reference passed to a subroutine reference?
body: <p>I have a function to convert documents into different formats, which then calls another function based on the type document. It's pretty straight forward for everything aside from HTML documents which require a bit of cleaning up, and that cleaning up is different based on where it's come from. So I had the idea that I could pass a reference to a subroutine to the convert function so the caller has the opportunity to modify the HTML, kinda like so (I'm not at work so this isn't copy-and-pasted):</p>
  
  <pre><code>package Converter;
  ...
  sub convert
  {
      my ($self, $filename, $coderef) = @_;
  
      if ($filename =~ /html?$/i) {
          $self-&gt;_convert_html($filename, $coderef);
      }
  }
  
  sub _convert_html
  {
      my ($self, $filename, $coderef) = @_;
  
      my $html = $self-&gt;slurp($filename);
      $coderef-&gt;(\$html); #this modifies the html
      $self-&gt;save_to_file($filename, $html);
  }
  </code></pre>
  
  <p>which is then called by:</p>
  
  <pre><code>Converter-&gt;new-&gt;convert("./whatever.html", sub { s/&lt;html&gt;/&lt;xml&gt;/i });
  </code></pre>
  
  <p>I've tried a couple of different things along these lines but I keep on getting 'Use of uninitialized value in substitution (s///)'. Is there any way of doing what I'm trying to do?</p>
  
  <p>Thanks</p>