note
tye
<p><em>
If you are a module, there is no need to do initializations in a BEGIN block.
</em></p><p>
Maybe you haven't found any but I certainly have. They aren't easy to run into but I still find it a valuable habit. Leaving a potentially large window for a race condition to fit into isn't my idea of a good programming technique. I suspect that future features of Perl will make this even more important to avoid.
</p><p>
Along those lines, I'd
<code>use base qw(Exporter)</code> myself, though I look forward to just being able to dispatch &import and avoid the sledgehammer of inheritance. (:
</p><p>
I consider qr// to be new enough of a feature that if I were to use it in a module I would make it optional:
<code>
BEGIN {
my $sub;
if( $] < 5.005 ) {
$sub= 'return $_[0]';
} else {
$sub= 'return qr/$_[0]/';
}
eval "sub _qr { $sub }; 1"
or die $@;
}
# ...
_split($text, map {_qr($_)} @_);
</code>
(untested, though).
</p>
-
<a href="/index.pl?node=tye&lastnode_id=1072">tye</a>
(but my friends call me "Tye")
47569
49053