-n forces the program to loop while there's still input from a.txt.

Yes but ...

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.

No. -n doesn't consider STDIN (thus b.txt) at all.

My assumption was that the two files are the same length as the OP made no mention of what should happen otherwise. But ...

If B is short than A, the last lines of A will be output with nothing from B.

If B is longer than A, the last lines of B will just be ignored (never read).

-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.

Yes, but I use printf rather than print which si not affected by the setting of the output record separator.

This may also chomp input from b.txt, but I'm unclear on that.

No. The record separator from b.txt is left in place when <STDIN> is read, so it provides the newlines for the output.

I don't understand why scalar is in place for the <STDIN> that is ingesting b.txt

Because printf provides a list context which would cause <STDIN> to slurp all of b.txt and append it to the first line of a.txt. By providing a scalar context it ensure that only one line is read from B for each line from A.

To those of us ... who don't often use the CLI, no, it's not quite as simple as it would seem to you.

I process lots of unstructured data; hence I use these facilities a lot and so I've become very familiar with this aspect of Perl. I guess it took your analysis of the one-liner to cause me to realise just how much implicit behaviour my "simple" one-liner made use of to do what it does.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

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