sbhar has asked for the wisdom of the Perl Monks concerning the following question:

Is their any way to include files like php include() function.Like for instance i have header.html footer.html body.html and i want to call these in a main.pl file,how to do it?

Replies are listed 'Best First'.
Re: How to include files in perl?
by davorg (Chancellor) on Mar 02, 2006 at 12:53 UTC

    Perl's equivalents of "include" are use, require and do. However, all of those methods expect the file that you're including to be Perl code, not HTML.

    So I think that perhaps you want to just open the files and read the contents. Or maybe you should be looking at Server Side Includes or a decent Templating system.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Re: How to include files in perl?
by davidrw (Prior) on Mar 02, 2006 at 14:41 UTC
Re: How to include files in perl?
by izut (Chaplain) on Mar 02, 2006 at 12:52 UTC
    You can use the do function. Please check perldoc -f do for more.

    Igor 'izut' Sutton
    your code, your rules.

Re: How to include files in perl?
by ambrus (Abbot) on Mar 02, 2006 at 14:33 UTC
Re: How to include files in perl?
by gube (Parson) on Mar 02, 2006 at 14:23 UTC

    Hi sbhar,

    In perl, you can read the content of the file and can print in the html page. Like the sample code above given by perlsen. And also, there is a module HTML::Template you can refer the link. There is a function 'TMPL_INCLUDE' using that you can include the files. It's very simple and effective module for the usage of htmls.

Re: How to include files in perl?
by perlsen (Chaplain) on Mar 02, 2006 at 14:01 UTC
      Using open without die is like making a peanut butter and jelly sandwich without peanut butter. You might not get what you expect.