in reply to Splitting program into modules

I have written a little sub that includes other files in your perl code. And I think, it's exactly what you need. Just try it and see if it works:



my $whatever = include('');


sub include{open my$H,'<:raw',$_[0];read($H,my$E,999999)or die"Error: Can't include \"$_[0]\"";close$H;eval$E;}

Replies are listed 'Best First'.
Re^2: Splitting program into modules
by Corion (Pope) on Nov 11, 2018 at 07:29 UTC

    Can you tell us how your code improves over do and require?

    Also, please note the limitations of your code, like that it doesn't handle files larger than a megabyte.

      Oh, yes, there seems to be no difference between include() and require. I haven't thought of that! :/
        > no difference between include() and require

        Actually you reimplemented do

        require is basically a do that searches through @INC and accepts module::names.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery FootballPerl is like chess, only without the dice