Just as an example:

Script file
my $file = "somefile.txt"; print "Opening and displaying $file:\n"; include($file); print "Complete\n"; exit; sub include { my $include = $_[0]; open(INFILE,"<$include") || die "Can't find or open $include\n"; @FileContent = <INFILE>; close(INFILE); foreach $line (@FileContent) { print $line; } }

somefile.txt
Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 Line 7 Line 8 Line 9 Line 10

Again, just as an example, and not exactly 'perfect'. As mentioned, there isn't any one way to do anything in Perl. This example, assumes that the file passed to the sub (function) include does not contain any program code, rather only information to display (which can be html code).

So, assuming your going to use this, you would copy the sub include to some file you include in your file/script, or in the primary file/script. Then place a call to include(), passing a single command, that being the file name to open, and display. Thus, the include() could be use in several locations, with each call to it having any file name you desire.

But as I said, this is just an example, and I should point out, not really clean. However, it does execute and displays 'correctly'. The output of this example:
Opening and displaying somefile.txt: Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 Line 7 Line 8 Line 9 Line 10 Complete

In reply to Re: PHP to PERL ? by Delusional
in thread PHP to PERL ? by brendgard

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.