- 论坛徽章:
- 0
|
再问一下,还有一点不明白。
cat data.txt
cdentA troteA cdentB troteB Type PubM
02995 4089 04484 4093 YH 16189514,15231748
01898 7429 00017 71 IV 3510866,6893424
02153 7114 00017 71 iV 15163409,10848969
03014 1173 03690 1856 yH 16189514
02319 10134 00017 71 iV 10958671
02458 9087 00017 71 iv 8416954
02549 4130 00017 71 iv 7820861
03014 1173 04318 10320 yh 16189514
02991 4306 00017 71 iv 8612804
cat test1
#!/usr/bin/perl
open(FH, '<', 'data.txt') or die "Cannot open data.txt: $!\n";
for (<FH>) {
my @fields = (split /\s+/)[0, 2];
print "@fields\n";
};
cat test2
#!/usr/bin/perl
open(FH, '<', 'data.txt') or die "Cannot open data.txt: $!\n";
while (<FH>) {
my @fields = (split /\s+/)[0, 2];
print "@fields\n";
}
这里for 和while 好像没什么区别,得出结果都有一样,应该怎么理解?
还有为什么有些行尾加不加 ; 号都可以呢? |
|