Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Splitting program into modules

by harangzsolt33 (Friar)
on Nov 11, 2018 at 03:50 UTC ( #1225557=note: print w/replies, xml ) Need Help??

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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2020-08-08 21:31 GMT
Find Nodes?
    Voting Booth?
    Which rocket would you take to Mars?

    Results (53 votes). Check out past polls.