perlquestion
Ovid
<p>Though I've already reported this bug, along with a fix, I have <em>no</em> idea how the fix works. I'm completely mystified. Here's a small test case:</p>
<code>package NoFilter;
use Filter::Simple;
FILTER_ONLY code => sub {};
1;</code>
<p>In other words, it filters nothing.</p>
<p>Here's my test code:</p>
<code>#!/usr/bin/perl
use NoFilter;
my $buf = <<HERE;
/
HERE
my $buf2 = <<HERE;
HERE</code>
<p>This generates the error:</p>
<code>substr outside of string at /usr/local/lib/perl5/5.8.7/Text/Balanced.pm line 70.</code>
<p>At first blush it looks like [dist://Text::Balanced] has a problem with the HERE docs (and historically it <em>has</em> had problems with HERE docs). However, there's a relatively easy fix for this. Opening up [dist://Filter::Simple] and adding <tt>&#91;$_&#93;</tt> as the first line of the anonymous subroutine which <tt>Filter::Simple::gen_std_filter_for</tt> returns:</p>
<code>sub gen_std_filter_for {
my ($type, $transform) = @_;
return sub {
[$_]; # XXX this is the "voodoo" line
my $instr;</code>
<p>And the problem mysteriously goes away. I have no frickin' idea why. Any clues? I've emailed [thedamian] about this but frankly, that's one heck of an embarrassing bug fix since it's "voodoo". Is there something bizarelly simple that I'm overlooking?</p>
<p>Side note: you can also have fun by deleting the "/" line in the first here doc. That generates other fun error messages.</p>
<p>This is perl, v5.8.7 built for darwin-2level. I'm using the latest <tt>Text::Balanced</tt> and <tt>Filter::Simple</tt>. I can replicate this problem on OS X and Fedora Core 2. A friend of mine <em>can't</em> replicate this on Perl 5.8.5 Redhat 4.0.</p>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-17000">
<p>Cheers,<br />
<a href="/index.pl?node=Ovid&lastnode_id=1072">Ovid</a></p>
<p><small>New address of <a href="http://users.easystreet.com/ovid/cgi_course/">my CGI Course</a>.</small></p>
</div></div>