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 :-)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.