See http://perlmaven.com/the-default-variable-of-perl, for example. (There are many other webpages that one can visit to get similar tutorials. This one was at the top of the Google search results.)

Also, you can Google "perl $_".

The short answer is it is a special variable in Perl.

Let us say, it is a special special variable in Perl.

For example, it can come into play when reading files.

Some beginners jump through hoops just to avoid using it.

In the case of your program, the record that is read from the file ends up in $_. I had to mimic that behavior in my test program. I put the data (i.e., the one record) into a variable called $record just because I like the descriptive name $record. I could have named it $milkshake but I didn't. Then I said Oh The program expects this data to be in the special variable $_, so I put $record into $_. Otherwise, the rest of the code is from your program. I just took a section of your code out and made another program and tested it to make sure that it does what I think it does.


In reply to Re^13: Addional "year" matching functionality in word matching script by Cow1337killr
in thread Addional "year" matching functionality in word matching script by bms9nmh

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.