How to include files in perl?
sbhar
created: 2006-03-02 07:38:07
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?
Re: How to include files in perl?
created: 2006-03-02 07:52:45
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?
created: 2006-03-02 07:53:32

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?
created: 2006-03-02 09:01:11
Hi,
Try this,
undef $/;
open (FILE,"/path/to/header.html");
my $file = ;
close(FILE);
print "$file"; 

Or Just Try for this links:
  • PHP include Modules
  • Include Virtual Files

  • Regards,
    Perlsen
    Re: How to include files in perl?
    created: 2006-03-02 09:23:09

    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?
    created: 2006-03-02 09:33:59

    Read this great tutorial: Including files.

    Re: How to include files in perl?
    created: 2006-03-02 09:41:14
    The Tutorials section answers that exact question in Including files w/several different methods (including modules, do, eval).

    See also last week's Using php like includes in perl script?

    perlmonks.org content © perlmonks.org and ambrus, davidrw, davorg, gube, izut, perlsen, sbhar

    prlmnks.org © 2006 edmund von der burg (eccles & toad)

    v 0.03