This is a great idea. I would just add a few comments that might clarify a few things for previous posts.

1. split /\s+/, $line; splits on any whitespace character, this includes space,\f,\r,\n,\t. Since \n is in this set, you don't need to chomp($part2); doesn't hurt but it is not necessary here. The reason in previous post that "\t" didn't work is that you need a regex for the first arg to split./\t/ would have worked but /\s+/ is usually better. The \t idea would result in a \n in $part2 and of course since you can't see these non-printing characters it is possible that there is are some plain spaces in there!

2.The best way to get the 2nd thing from the split is with list slice. my $part2 = (split /\s+/, $line)[1]; Since you don't use $part1, there is no need to assign it. It often occurs that you are working with a line with a bunch of things on it and you just want a couple of them. Using list slice allows you to assign meaningful names to these things like maybe: my($temperature,$city)=(split /\s+/,$line)[3,8];. This is a lot better than say, $line[3] because you don't need any comments to explain that thing 3 means temperature.

Of course here the op probably has some other name in mind for $part2 that would make the code even more clear.


In reply to Re^2: Read two files and print by Marshall
in thread Read two files and print by sandy1028

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.