One difference between the one liner and your code (other than the original one liner prints the last 200 instead of the last 20 lines) is that the original one-liner handles files having less than 200 lines gracefully. If "screenlog.0" has less than 200 lines, your code will spit out a warning and a blank line of each line "missing". That is, if screenlog.0 only has 30 lines, the original shell one liner will put 30 lines in screenlog, and generate no warnings, while your code will issue 170 warnings, and put 170 additional blank lines in "screenlog".

Shell commands rewritten in Perl will often seem horribly verbose, but don't be discouraged.
I'd say, if you want to rewrite shell commands in Perl, think twice, don't do it, and if you insist and need advice, get that advice from shell experts.

In reply to Re^2: Mini bash script to perl by JavaFan
in thread Mini bash script to perl by Anonymous Monk

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.