There are a number of ways to improve your script.

First, always use strictures (use strict; use warnings;). They pick up typos and give early warning of trouble ahead.

Always use the three parameter version of open which gives better security and makes the intent clearer. Check the result of opens and closes - again you get an early heads up about trouble. Use lexical file handles to better manage the life time of the opened file handle.

Never use $a or $b as general purpose variables - they are special and should only be used with sort. In fact, avoid single letter variable names in general - it's too easy to get them confused with each other.

Be consistent with your use of indentation and white space. PerlTidy is a really good tool - use it.

Avoid .*? in regular expressions. Instead use a negated character class: [^\n]*. Only capture stuff you actually want to use - it's more efficient and less confusing.


True laziness is hard work

In reply to Re: content extraction by GrandFather
in thread content extraction by zzgulu

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.