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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |