The post that I made is runnable code. If you download it, it will run "as is". I hope that you did that!

Instead of an actual data file, I used the predefined DATA file handle. The data that is being read is right after the __DATA__ statement. This allows me to make a single post that shows the program, the output, and the input data.

What Perl does is open the .pl program for read and then "seeks" to the beginning of the line right after __DATA__. The DATA file handle is initialized by Perl without me doing anything extra. Pretty cool! As trivia, it is possible to "seek" the DATA file handle to the beginning of the file. This would allow a Perl program to actually "read itself".

To make a "real program", you need to put in something like this:

open FILE, '<', "yourfilename" or "die unable to open read file $!";
Now put FILE everywhere that I used DATA.

The other "trick" that I used was perldoc. Perl has a way of embedding documentation right into the program. There is a utility that generates nicely formatted documentation and HTML pages using certain markup tags. The "=prints" says that what follows is documentation. The "=cut" says "end of documentation". So everything between and including the =prints and =cut tags is skipped by the compiler because it figures that this is program documentation.

Asking questions if you see something that you don't understand is fine. I can't predict in advance what you know or don't know.


In reply to Re^3: Perl Formatting Text by Marshall
in thread Perl Formatting Text by oopl1999

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.