Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: conditional enable use bytes for a whole module at compiletime?

by bpphillips (Friar)
on Nov 19, 2004 at 13:55 UTC ( [id://408999]=note: print w/replies, xml ) Need Help??


in reply to Re: conditional enable use bytes for a whole module at compiletime?
in thread conditional enable use bytes for a whole module at compiletime?

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 :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://408999]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (1)
As of 2024-04-25 01:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found