First of all, the Perl code-fragment you have provided is not related to “a C function.” That sort of thing is provided by a sub.

The Perl fragment that you have provided first declares five private variables, then enters a loop that reads a line of data from the standard-input. What might be throwing you off here is that there seem to be no actual references to the file, nor to the record that has been read from it, nor to the reading! Perl is big on “shorthand,” and it's very much a purpose-built language; its purpose is text-processing.

So the while-loop is reading from a file, and each of the if statements contain “regular expressions” (string patterns), which implicitly (because they do not use the operator =~) refer to the latest line that has been read from the input. (This line is contained in the very strangely named variable, $_. Don't ask me why Perl uses such odd names; maybe Larry Wall can't type good. I'm also not a fan of its insistence upon “funny characters” like $, @, % but once again it wasn't my idea...)

Some of the constructions in that Perl fragment are peculiar; in fact, the entire flow-of-control seems strange to me.

Anyhow, “Perl is what Perl is,” and even though the syntax of the language may throw you off for a few moments, your existing familiarity with embedded-C will soon come roaring back. Probably the most peculiar aspect of this language from that perspective is that, whereas “C” does almost-nothing for you, Perl does quite a lot. Garbage-collection and automatic memory management, for example; built-in hashes; a fairly-clever “reference” system for safe indirect addressing. Don't look at the Perl-5 source code unless you have a strong stomach... although you with your experience may well find it informative.


In reply to Re: help with perl understanding by Anonymous Monk
in thread help with perl understanding by barryscott

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.