Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Splitting program into modules

by harangzsolt33 (Pilgrim)
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:

include('database.pl');

OR

my $whatever = include('getTime.pl');

...

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2019-09-17 07:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The room is dark, and your next move is ...












    Results (202 votes). Check out past polls.

    Notices?