Syntactic Confectionery Delight | |
PerlMonks |
Re^4: Use 2 files and print each line of each one side-by-side (One-liner)by jellisii2 (Hermit) |
on Feb 19, 2014 at 13:28 UTC ( [id://1075450]=note: print w/replies, xml ) | Need Help?? |
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 Section
Seekers of Perl Wisdom
|
|