in reply to Re^2: impose 'use bytes' on another package
in thread impose 'use bytes' on another package

You don't have to remove trailing true value and it'd have been nicer if you avoided making a call to the shell and cat when there are perfectly good perl functions for such a thing. This is also a quick and dirty solution but it isn't as craptacular as yours.

local @ARGV = "Foo.pm"; # TODO: make this search @INC local $/; eval "#line Foo.pm 1\nuse bytes;" . <>; die $@ if $@;

⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Replies are listed 'Best First'.
Re^4: impose 'use bytes' on another package
by codeacrobat (Chaplain) on Apr 06, 2006 at 06:32 UTC
    I agree your solution works better.
    use Foo; my ($foo) = grep {/Foo\.pm$/} values %INC; { # so that local can be local local @ARGV = $foo; local $/; eval "#line Foo.pm 1\nuse bytes;" . <>; } die $@ if $@; print Foo::len(); # prints 2
    In this version however you have to reuse the module, which can be problematic.

      You'll want to search @INC, not the values of %INC. %INC is what has been loaded in the current script and doesn't contain a list of directories to search.

      ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊