Since the OP's sub l is within the same BEGIN block as use bytes this isn't really the issue (although placing the use bytes alone in the begin block causes the pragma to be scoped only to the BEGIN block. I remembered seeing an example of this type of thing in the source of RPC::XML. I'm guessing there's no simple way around the problem but here's one option (which you might have already discovered based on your original post):
package Y;
$VERSION = 0.1;
1;
package X;
my $subs =<<__SUBS__
sub l{ return length shift };
__SUBS__
if ( $Y::VERSION < 1 ){
use bytes;
eval $subs;
} else {
eval $subs;
}
+
+
# large module follows
+
+
1;
package main;
no bytes;
$x = chr(3456);
print X::l($x);
BTW, use MODULE is the different than use PRAGMA. You can't use BEGIN { require PRAGMA import PRAGMA LIST; } when you're dealing with pragmas. The BEGIN {} creates a lexical scope of it's own and defeats the purpose of pragmas that affect the lexical scope. Plus, you wouldn't ever be able to do an import on the pragma.
Update: Solutions suggested below using the if module are much more reasonable than what I posted... Oh well :-)
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|