I seldom do oneliners myself, and never anything this clever, but let me attempt to noodle out what's going on here as an exercise for myself. None of this should come as a surprise to those who have serious depth in perl, particularly those who do lots of CLI work, but it will be enlightening to me.

-n forces the program to loop while there's still input from a.txt. I assume this also takes into account input from <STDIN> as well in the event b.txt is longer than a.txt, but I'm unclear on that point.

-l tells perl that a carriage return is the record separator, and chomps each line from a.txt, and sets the output record separator to the same, so each line printed should have a carriage return. This may also chomp input from b.txt, but I'm unclear on that.

The formatting of the print statement is pretty obvious to me, but for completion's sake, the format is 10 characters (with right padding of spaces if the string is short), a tab, and another 10 characters.

$_ is the current line from a.txt, and will be used left of the tab in the formatted print.

I don't understand why scalar is in place for the <STDIN> that is ingesting b.txt from the shell's redirect. Assuming this works as advertised (not that I have any real doubt), it will be used in right of the tab in the formatted print.

To those of us (it may just be me, who knows) who don't often use the CLI, no, it's not quite as simple as it would seem to you. I get that "knowing the tool" is important, and strive to learn more as I go, but the reality is that there's a LOT baked into perl to learn. Between this fact, the habit to "stick with what works", and that my job nor hobby is %100 perl, I freely admit my education/depth/knowledge may be a bit lopsided. I think this would apply to a majority of the monks in the monastery to some degree.

Thank you for the enlightenment.


In reply to Re^4: Use 2 files and print each line of each one side-by-side (One-liner) by jellisii2
in thread Use 2 files and print each line of each one side-by-side 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.