I am new to perl as of a couple weeks ago.
If it's easy, I would like to truncate an html file that I'm continuously adding one line of information to the top of. I would like to keep this file just 5 "lines" long. Lines are separated by an html line break in this case, not a new line character.
The html file is text only with no tags or formatting and completely empty at the start of the process.
New lines are added to the file such that $html_doc = "a new set - line 1 {br} $html_doc"
After 6 additions to the file, it looks like: (note: curly brackets are used below instead of < and > to illustrate)
a new set - line 6 {br}a new set - line 5 {br}a new set - line 4 {br}a new set - line 3 {br}a new set - line 2 {br}a new set - line 1
in a browser the file looks like:
a new set - line 6
a new set - line 5
a new set - line 4
a new set - line 3
a new set - line 2
a new set - line 1
I would like to use the simplest way to chop off anything past the 5th line break, IF there are that many lines. Otherwise, the entire file can stay as is.
Is there an easy way to do this?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.